没有内置这样的东西,并且跟踪仅存储在另一个方向:“X跟踪Y”,而不是“Y被...跟踪”,这更复杂,因为“...”部分可以扩展为不止一项。(此外,我认为 Y 首先是远程跟踪分支更为典型,在这种情况下,您永远不可能在 Y 上——尽管尝试查找“Y 跟踪什么”的命令肯定会占用论点,所以你可以说“告诉我我跟踪的任何分支origin/master
)。
也就是说,当然可以建造这样的东西。该算法看起来像这样,在 Python 式的伪代码中:
table = {}
for branch in local_branches:
try:
remote, tracked = get_what_branch_tracks(branch)
except ValueError:
continue # local branch "branch" not tracking anything
try:
br2 = analyze(branch, remote, tracked)
except ValueError:
warn('upstream for %s is gone' % branch)
continue
# at this point br2 is, e.g., origin/master or a local branch that "branch" tracks
table.setdefault(br2, []).append(branch)
# now table[] is a table of branches that are tracked, with
# each table[key] being the branches that track branch "key"
因此,现在对于 中的任何有趣的分支table
,您只需计算在各种分支对中可找到的修订,方法相同git status
,在 shell 中只是:
# to compute "git status" for branch X that tracks Y:
nahead=$(git rev-list --count Y..X) # we're ahead $nahead commits
nbehind=$(git rev-list --count X..Y) # and behind $nbehind
如果你落后但不领先,你可以快进。
for 的细节get_what_branch_tracks
只是简单地做一些git config --get
s, of和 of ,而 for 的细节更复杂:if is then what is in很简单,但如果它是一个实际的遥控器,无论是 in必须通过相应的行才能找到适当的远程跟踪分支。branch.branch.remote
branch.branch.merge
analyze
remote
.
tracked
tracked
fetch