Git 命令笔记

使用 git 一些命令记录,方便分支管理,用于了解一些不常见的 git 命令用法。

  1. 删除远程已删除分支
  2. 本地分支按最后提交时间排序
  3. 查看只存在本地的 tag
  4. 查看指定版本文件内容
1. 远程已删除分支,本地依旧存在

远程分支删除后,git branch -a 还是会显示,使用以下命令清除

# git remote prune <remote name>
git remote prune origin
2. 本地分支按最后提交时间排序

本地分支越来越多,最后清理时,希望通过最后提交时间排序来显示

# format 可以根据自己需要进行修改,以下命令是 提交年月日和分支名
# 修改 refs/heads 为 refs/remotes/origin/ 可以查看远程 origin 仓库分支排序
git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
3. 查看只存在本地的 tag

使用 tag 标记了部分本地提交,可使用以下命令找出来

git ls-remote --tags gerrit | git show-ref --tags --exclude-existing
4. 查看指定版本文件内容
# 1. git show 查看本地仓库文件
git show <commit/branch>:path/to/file
# 2. git archive 获取远程代码库文件
git archive --remote=ssh://git@HOST:PORT/path/to/project.git BRANCH_NAME:path/to/dir file | tar xO
# OR
git archive --remote=ssh://git@HOST:PORT/path/to/project.git BRANCH_NAME path/to/file | tar xO
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值