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
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).
I was incorrect with my original answer. You want the double dot notation:
git log master..<your_branch_name>
I got different results than I was expecting, so I did a test with the following repo structure:
a - - c - e - - g - i master
\ b - d / \ f - h test
I then tried git log master..test
:
f - h
And then git log master...test
:
- g - i
f - h
So double dot shows the commits in test
but not in master
(^master temp
) and triple dot shows commits in master
AND test
but not in both.
The other excellent answer in this question got it right first and has a better explanation (https://stackoverflow.com/a/24769534/1185838); it should probably be marked as the answer instead of mine. You can also reference this answer (https://stackoverflow.com/a/463027/1185838) which helped me better understand the difference between double dot and triple dot notation.
Apologies for the incorrect answer!
Old Answer - Incorrect
Use three periods to reference the commit at which the second branch diverged from the first, or in this case your branch diverged from master:
git log master...<your_branch_name>
Make sure to use three periods for this case.
Side-Note: You can also leave off your branch name as git automatically references the HEAD pointer in that case, for example:
git log master...
is equivalent to my previous example. This works anywhere a commit comparison is available.
If you're on the branch that you created:
git log master..
Yes it's possible to compare your "new" branch with the master branch (commonly named : "master"):
git log master..<your_branch_name>
Of course, replace <your_branch_name>
.