How to find out how many places a local branch in front of / behind another local branch in git makes?

If I am working on a function branch, I would like to know how many of them this branch commits in front of or behind the leading branch. I can't seem to find a team that does this.

+4
source share
2 answers

Listing and counting commits: git rev-list

A quick way is to do what it git statusdoes when there is an upstream. In particular, it git statussimply counts revisions that are in the current branch, which are not in the upstream branch. For example, consider a branch foothat has upstream origin/foo, and suppose you made three local commits, and then used git fetchto bring up one upstream commit:

              L - L - L   <-- foo
            /
... - C - C
            \
              U           <-- origin/foo

Here Care common commits, Lare local commits, and Uis an upstream commit. If you are on a branch fooand you run git status, you will see "ahead of 3, for 1".

Here git gets these numbers:

  • git rev-list foo --not origin/foo: foo, origin/foo. , origin/foo ( U), : U C . foo , : L .

  • --count git rev-list, SHA-1 .

  • git rev-list origin/foo --not foo: , origin/foo, foo, U. ( --count, , .)

, foo --not origin/foo origin/foo..foo gitrevisions . ( git status , HEAD - . @{upstream} @{u} HEAD , , git status git rev-list --count ..@{u} git rev-list --count @{u}...)

rev-list , vs git cherry

, , feature, master, , feature master. git rev-list master..feature , feature, master, --count :

git rev-list --count master..feature

, , diff, "". , , feature , master did't, ( -) , master, :

              D - E - F - G - H   <-- feature
            /
... - C - C
            \
              F'                  <-- master

F' - commit F. git rev-list feature, master, 5; git cherry feature, master, commit F , , F' F. , git cherry, 4, 5.

+4

git cherry, , ,

git cherry -v master feature

, , .

,

git cherry -v feature master 

, , .

.

git cherry -v feature master 1b219e

UPDATE:

,

[alias]
    mydiff = !sh -c 'echo "Commits in $2 not in $1" && git cherry -v $1 $2 && echo "Commits in $1 not in $2" && git cherry -v $2 $1' -

git mydiff master feature
+3

All Articles