简体   繁体   English

不一致的 git rev-list 计数

[英]Non consistent git rev-list count

I am working on a zsh custom prompt and I am trying to show how many commits ahead and behind remote my branch is.我正在处理 zsh 自定义提示,我试图显示我的分支前后有多少次提交。 For that I use the following command为此,我使用以下命令

git rev-list --left-right --count main...origin/main

Which returns ab where a are the commits local is ahead of remote, and b are the commits remote is ahead of local.它返回ab其中 a 是本地提交在远程之前,b 是远程提交在本地之前。

I have found an inconsistency I cannot properly understand.我发现了一个我无法正确理解的不一致之处。 Reproduction code below复制代码如下

git clone https://github.com/numpy/numpy
cd numpy
git rev-list --left-right --count main...origin/main
#  0     0  # As expected

git reset --hard HEAD~10
git rev-list --left-right --count main...origin/main
#  0     31  # Whaaaaaaat?

Can somebody help me understand what am I missing?有人可以帮我理解我错过了什么吗?

Thanks谢谢

As phd noted in comments , removing one merge commit from reachability by some branch name will generally remove multiple commits from reachability.正如phd 在评论中指出的那样,通过某个分支名称从可达性中删除一个合并提交通常会从可达性中删除多个提交。 Given that the numpy repository has a lot of merges on its main branch, the result you saw was unsurprising.鉴于 numpy 存储库在其主分支上有很多合并,您看到的结果并不令人惊讶。

Here is an illustration (not meant to be specific to the numpy repository) where removing one merge commit removes four commits from reachability:这是一个说明(并非特定于 numpy 存储库),其中删除一个合并提交会从可访问性中删除四个提交:

...--G--H------L--M   <-- main (HEAD), origin/main
         \       /
          I--J--K   <-- feature

Branch feature was just merged to branch main (and then pushed), so commits M , L -and- K , J , I , H , G , and so on are all reachable, working backwards, from commit M to which main points.分支feature刚刚合并到分支main (然后推送),因此提交ML -and- KJIHG等等都是可以访问的,从提交M到哪个main向后工作。

Making main point directly to L , as we'd get with a git reset --hard HEAD~1 , removes commit M from main , but also removes commits IJK .直接指向L ,就像我们使用git reset --hard HEAD~1 main main删除提交M ,但也删除提交IJK So after this reset you'll be "zero ahead" and "four behind" origin/main .因此,在此重置之后,您将“领先零”和“落后四” origin/main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM