git branch -v、git branch -vv、git branch -verbose

本文深入讲解了使用Git进行分支管理的技巧,特别是如何利用-verbose选项查看本地分支与远程分支的关系,包括它们之间的相对位置、超前或落后状态。通过具体示例,展示了如何结合使用-v和-a选项来获取详细的分支信息,帮助开发者更好地理解并维护项目中的分支结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

git文档

git branch
-v
-vv
--verbose
When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well (see also git remote show <remote>).

翻译说明

显示每个(本地)分支当前指向的提交记录的哈希值,以及和其上游分支的相对位置(如果有的话)
-v-verbose是一个效果
-vv会显示上游分支的名字

举例

$ git branch -vv
  cyr_branch   689c970 [origin/cyr_branch: behind 2] default
* master       f1e2810 finally
  test-mysql   e2fa7b9 add .gitignore
  test-network 0d426ce add .gitignore
  xu_branch    e55fcf1 [origin/xu_branch: ahead 1] debug
  zfc_branch   e4a40a5 [origin/zfc_branch] merge

cyr_branch的上游分支为origin/cyr_branch,前者落后后者2
xu_branch的上游分支为origin/xu_branch,前者领先后者1
zfc_branch的上游分支为origin/zfc_branch,两者同步
test-mysqltest-network没有对应的上游分支
master的上游分支为origin/master,但是没有显示,我猜测是因为这个对应关系是固定的,所以无需显示

组合用法

-a 显示所有本地及远端分支名

$ git branch -a
  cyr_branch
* master
  test-mysql
  test-network
  xu_branch
  zfc_branch
  remotes/origin/cyr_branch
  remotes/origin/master
  remotes/origin/xu_branch
  remotes/origin/zfc_branch

-av

$ git branch -av
  cyr_branch                689c970 [behind 2] default
* master                    f1e2810 finally
  test-mysql                e2fa7b9 add .gitignore
  test-network              0d426ce add .gitignore
  xu_branch                 e55fcf1 [ahead 1] debug
  zfc_branch                e4a40a5 merge
  remotes/origin/cyr_branch 1e63522 cyr
  remotes/origin/master     f1e2810 finally
  remotes/origin/xu_branch  1c82da3 adjust db
  remotes/origin/zfc_branch e4a40a5 merge

-avv

$ git branch -avv
  cyr_branch                689c970 [origin/cyr_branch: behind 2] default
* master                    f1e2810 finally
  test-mysql                e2fa7b9 add .gitignore
  test-network              0d426ce add .gitignore
  xu_branch                 e55fcf1 [origin/xu_branch: ahead 1] debug
  zfc_branch                e4a40a5 [origin/zfc_branch] merge
  remotes/origin/cyr_branch 1e63522 cyr
  remotes/origin/master     f1e2810 finally
  remotes/origin/xu_branch  1c82da3 adjust db
  remotes/origin/zfc_branch e4a40a5 merge

转载于:https://www.cnblogs.com/milesgo517/p/10992598.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值