69

If my-feature-branch was merged into my-main-branch, how can I see what commits were merged in from my-feature-branch?

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
The Pixel Developer
  • 13,282
  • 10
  • 43
  • 60

3 Answers3

82

git log abc123^..abc123
shows the commits that got merged into merge-commit abc123.

Create a git alias log-merge for easy reuse:

$ git config --global alias.log-merge \
'!f() { git log --stat "$1^..$1"; }; f'
$ git log-merge abc123

For a one-line version:

$ git config --global alias.log-merge-short \
'!f() { git log --pretty=oneline "$1^..$1"; }; f' 
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Jesse
  • 6,725
  • 5
  • 40
  • 45
  • This solution is great. I modified a version of the command so we could get a "short" version: `$ git config --global alias.merge-log-short '!f() { git log --pretty=oneline "$1^..$1"; }; f'` – glade Feb 28 '20 at 18:03
52

If you want to see every commits merged in the last merge you can try that :

git log $(git merge-base --octopus \
$(git log -1 --merges --pretty=format:%P)).. --boundary

Here is an example of my current log :

$ git log --graph --pretty=oneline --abbrev-commit
* 44899b9 pouf
*   8f49f9c Merge branch 'test'
|\  
| * 3db39ca test
* | 69f431c pif
* | df1f51c lala
|/  
* 8fae178 pif2
* 20f8ba6 init

If I only want commits related to the last merge I have to use git log -1 --merges --pretty=format:%P which gives me the parents of the first merge available :

$ git log -1 --merges --pretty=format:%P
69f431cec7859b61d33c7503c9431ceea2aaf3e0 3db39ca3ab1e8f70462db23d94590628b5e7ad7b

Now that I know which parents I need to track, I need their common base that I can obtain through git merge-base --octopus (--octopus is there just in case) :

$ git merge-base --octopus \
$(git log -1 --merges \
--pretty=format:%P)
8fae178666e34a480b22e40f858efd9e7c66c3ca

Now with git log I can search every commit since the base to the current HEAD:

$ git log $(git merge-base --octopus \
$(git log -1 --merges --pretty=format:%P)).. \
--boundary --graph --pretty=oneline --abbrev-commit 
* 44899b9 pouf
*   8f49f9c Merge branch 'test'
|\  
| * 3db39ca test
* | 69f431c pif
* | df1f51c lala
|/  
o 8fae178 pif2

If you're a bit perfectionist you can also do this :

$ git log 
$(git merge-base --octopus \
$(git log -1 \
--merges --pretty=format:%P))..$(git log -1 --merges --pretty=format:%H) \
--boundary --graph --pretty=oneline --abbrev-commit 
*   8f49f9c Merge branch 'test'
|\  
| * 3db39ca test
* | 69f431c pif
* | df1f51c lala
|/  
o 8fae178 pif2

Now I think I'll keep this as an alias :)

The --graph --pretty=oneline --abbrev-commit options are optional.


Resources :

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
  • `git log --graph --oneline` is a shortcut for `git log --graph --pretty=oneline --abbrev-commit`. – Tal Jacob - Sir Jacques Apr 18 '22 at 20:25
  • I made this answer more comfortable for daily use [in this repository](https://github.com/taljacob2/git-log-merge). You are welcome to use this. – Tal Jacob - Sir Jacques Apr 18 '22 at 22:02
  • This includes a lot more commits than the top voted answer. If I remove `--boundary` then I get the same number, but I don't know why as I don't fully understand all the pieces involved. – bmaupin May 31 '23 at 15:10
0

If you have a merge commit (say a2345) and say git log -1 a2345, it will tell you the names of the parents (i.e. the commits which got merged in this commit). Is that what you're looking for?

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • Yep, that's what I wanted (only showing 1 commit though). I assume you can do this for the normal git log view too? – The Pixel Developer May 31 '11 at 17:27
  • Yes. If you want to browse parents of a larger number of commits, the GUI (gitk) is more useful. The restriction to a single commit is because of the `-1`. Drop that and you'll get the regular log. – Noufal Ibrahim May 31 '11 at 17:43
  • if I drop the `-1` it shows all the log of all commit messages, this seems not useful – knocte Feb 27 '17 at 04:28