git: programmatically know by how much the branch is ahead/behind a remote branch

后端 未结 10 725
南方客
南方客 2021-01-30 10:29

I would like to extract the information that is printed after a git status, which looks like:

# On branch master
# Your branch is ahead of \'origin/         


        
10条回答
  •  忘掉有多难
    2021-01-30 11:09

    git rev-list origin..HEAD will show the commits that are in your current branch, but not origin -- i.e., whether you're ahead of origin and by which commits.

    git rev-list HEAD..origin will show the opposite.

    If both commands show commits, then you have diverged branches.

提交回复
热议问题