Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

git - show commits since branch creation

Is there a way to see with git log or some other command only the commits that were added after branch creation?

usage: git log [<options>] [<since>..<until>] [[--] <path>...]
   or: git show [options] <object>...

    --quiet               suppress diff output
    --source              show source
    --decorate[=...]      decorate options
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Full documentation is here: https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html

Suppose you have a repo that looks like this:

base  -  A  -  B  -  C  -  D   (master)
                
                 -  X  -  Y  -  Z   (myBranch)

Verify the repo status:

> git checkout master
Already on 'master'
> git status ; git log --oneline
On branch master
nothing to commit, working directory clean
d9addce D
110a9ab C
5f3f8db B
0f26e69 A
e764ffa base

and for myBranch:

> git checkout myBranch
> git status ; git log --oneline
On branch myBranch
nothing to commit, working directory clean
3bc0d40 Z
917ac8d Y
3e65f72 X
5f3f8db B
0f26e69 A
e764ffa base

Suppose you are on myBranch, and you want to see only changes SINCE branching from master. Use the two-dot version:

> git log --oneline master..myBranch
3bc0d40 Z
917ac8d Y
3e65f72 X

The three-dot version gives all changes from the tip of master to the tip of myBranch. However, note that the common commit B is not included:

> git log --oneline master...myBranch
d9addce D
110a9ab C
3bc0d40 Z
917ac8d Y
3e65f72 X

PLEASE NOTE: git log and git diff BEHAVE DIFFERENTLY! The behavior is not exactly opposite, but almost:

> git diff master..myBranch
diff --git a/rev.txt b/rev.txt
index 1784810..e900b1c 100644
--- a/rev.txt
+++ b/rev.txt
@@ -1 +1 @@
-D
+Z

> git diff master...myBranch
diff --git a/rev.txt b/rev.txt
index 223b783..e900b1c 100644
--- a/rev.txt
+++ b/rev.txt
@@ -1 +1 @@
-B
+Z

So, the two-dot version shows the diff from tip of master (i.e. D) to tip of myBranch (Z). The three-dot version shows the difference from the base of myBranch (i.e. B) to the tip of myBranch (Z).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...