Reputation: 11890
Let's say I have a git branch and I'm working on a large feature, so periodically I keep it up to date with master
by running git merge master
.
Merging in master
brings in a lot of different commits, so when I do git log
I'm getting an intertwined history of my personal commits on "this branch" and also several miscelalneous commits from master
Is there a way to view only the history on "this" branch?
Does git natively track which parent in a merge is a "primary" one and which one was "merged in" to the other? If so it should be possible to traverse the history to only follow the "primary" parents at each merge point right?
Thanks!
Upvotes: 2
Views: 748
Reputation: 1001
you can use
git log origin/master.. --no-merges
so it will show only commits that are in your dev branch that are not in master. furthermore with the flag --no-merges
it won't print commits with more than one parent.
the answer to your second question is yes, in a merge commit the base branch "is" the first parent and the branch you are merging to it "is" the second one (to put it in a simple way); so to follow only the first parent when looking for revisions you can use the flag --first-parent
.
this means if you have this history:
* a953ca2 Merge remote-tracking branch 'origin/WildBranch'
|\
| * b5399f7 Commit to WildBranch: 1483140838
| * 30f181d Commit to WildBranch: 1483140837
| * 5f18ce9 NEW BRANCH: WildBranch
* | 42554e5 Commit to master: 1483140840
* | d512b35 Commit to master: 1483140839
|/
* 5f2e69e Commit to master: 1483140836
so if i'm standing in a953ca2
, the merge commit, the first parent is the last commit done in master (^1
means the first parent of this commit):
$ git log --pretty=format:"%h" a953ca2^1 -1
42554e5
while the second one is where HEAD was aiming in your dev branch when you merged it to master (^2
means the second parent of this commit):
$ git log --pretty=format:"%h" a953ca2^2 -1
b5399f7
if you are standing in master and use the --first-parent
option it will follow only those commits in the revision:
$ git log --first-parent --pretty=format:"%h" a953ca2 -4
a953ca2
42554e5
d512b35
5f2e69e
Upvotes: 7