show commits since branch creation
Asked Answered
A

7

106

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
Alsatia answered 15/3, 2012 at 18:3 Comment(2)
F
102

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).

Forequarter answered 15/7, 2014 at 22:57 Comment(3)
If you would do git log --oneline myBranch..master, would that give you D and C?Rudich
upvote for describing the difference between .. and ... and providing examples. Awesome answer!Orran
Thanks for pointing out log and diff behave differently (almost oppositely). Why would that be?Affer
A
72

You want the double dot notation:

git log master..<your_branch_name>

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://mcmap.net/q/66568/-show-commits-since-branch-creation); it should probably be marked as the answer instead of mine. You can also reference this answer (https://mcmap.net/q/12241/-what-are-the-differences-between-double-dot-quot-quot-and-triple-dot-quot-quot-in-git-commit-ranges) which helped me better understand the difference between double dot and triple dot notation.

Aborn answered 3/1, 2013 at 22:36 Comment(4)
git log master... did NOT work for me, only git log master.. worked. Notice the two dots instead of threePortuguese
Glad it worked for you. Double for is obviously correct syntax. But be careful, the dots DO matter. See Alan Thompson's answer for a detailed explanation of the difference between the double and triple dot notation.Aborn
This gives me odd results... While master..mybranch gives 1 (and there is indeed just one commit since branch creation), your version with three dots gives me 35. Where that 35 comes from is unclear. Looks like it counts all commits that happened on master since the branch was created. Or maybe both on the branch and on master...Caracul
If this doesn't work for you, consider whether maybe you meant origin/master instead of the local one (if that is the case, as it was for me, you can simply do origin/master..mybranch)Spectator
M
18

If you're on the branch that you created:

git log master..
Monospermous answered 26/11, 2015 at 2:9 Comment(0)
H
5

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>.

Hardness answered 15/3, 2012 at 18:11 Comment(1)
This only shows the commits since you last pulled from master, or vise versa, which is not the same as showing the commits since the branch was created.Sahara
C
0

I could be wrong but I don't think any of the answers are exactly was being asked for in the OP so I wanted to add a new answer. I believe that this is the exact same question I had since in other source control systems this is very easy to do.

I have the following in MASTER:

'develop' | --> 'GP603'

In ORIGIN (my local system) I have:

'GP603' [CLONED from the remote/GP603 branch]

I then performed 2 different commits. First commit change File X. Second commit change File X and File Y. Some day later I wanted to just validate my assumption of the state of the local branch ORIGIN/GP603. This is what I did to validate that there were only he 2 commits I remembers doing (which in reality were the only 2 commits on the branch)

$ git log origin/GP.603...

(Commit 2) commit b0ed4b95a14bb1c4438c8b48a31db7a0e9f5c940 (HEAD -> GP.603) Author: xxxxxxx Date: Wed xxxxx -0400

1. Fixed defect where the format of the file names and paths were being added to HashTable in such a way that they would never be matched in any comparison.  This was an
defect causing older failed files to never be moved to the correct directory (WindowsServiceApplication.cs)

2. Removing worthless and contextless message as it does nothing but clog the log with garbage making it harder to read (DinoutFileHandler.cs)

(Commit 1) commit 2c4541ca73eacd4b2e20d89f018d2e3f70332e7e Author: xxxxxxx Date: Tue Oct xxxxx -0400

In ProcessFile() function need to perform a .ToLower() on the file path string when adding it o the failedFiles collection.
Cadge answered 17/10, 2018 at 20:31 Comment(0)
O
0

This command worked nicely for me. I was interesting in seeing only the names of the files that changed in the delta of commits between a beginning and an ending ref,

 git log --no-merges --pretty=oneline --name-only <begin ref>..<end ref>

which gives output like this,

<commit hash> <commit subject line>
foo.txtr
bar.txt
Olander answered 13/10, 2020 at 15:11 Comment(0)
T
-1

I get often into the mode of oh, dear God, what have I done. Specifically, the haunting fear regards the latest changes in the current branch. It's nice to see the blame game of commits, which I do as follows. (Assuming you're in the current branch of interest and have branched it out from dev.)

git log --oneline dev..

It gives me the list of commits I've done to track back to the place where mayhem, sodom and gomorra aren't the reality. Also, it helps if you commit obsessively like a ADHD monkey on LSD. Once I've got my bearings list, I can narrow it down and analyse as documented in this article - there's a section on limiting the output at the bottom.

Transverse answered 15/3, 2020 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.