1

May be its asked already but I couldn't find it in here.

I have a branch FEATURE merged into a branch STABLE and currently when I do git show from STABLE am getting the last commit which is

commit 265d684b67e66ba762bd438c44e49881f7fd571b
Merge: 5285837 78d9687
Author: xxxxx
Date:   Thu Sep 6 18:58:46 2012 -0400

    Merge branch 'FEATURE' into STABLE

Couldn't figure out how to find who last committed what change to the FEATURE branch before its merged to STABLE?

This is needed to send a notification to the committer who lastly committed some changes.

Let me know if any further info required and any help/suggestions would be appreciated?

raksja
  • 3,969
  • 5
  • 38
  • 44
  • I'm having some problems understanding your actual problem. What exactly is keeping you from looking at the last commit before the merge? Are you asking how to parse the appropriate informations? – Grizzly Sep 06 '12 at 23:33
  • @Grizzly Exactly thats what I'm looking, the parsing of informations. Not only have only FEATURE branches merged in STABLE I also have several types of branches merging/changing the content of STABLE. I am trying to get out some info from the answers provided. Thanks for your reply. – raksja Sep 06 '12 at 23:49

3 Answers3

3

Not exactly what you're looking for, but to print out all remote branches and their last commit's author, I used the following command on Bash:

IFS=$'\n' && for branch in $(git branch --all | grep "remotes/origin" | sed "s/->.*$//" | sort); do echo "$(git log --format=format:"%an" ${branch//[[:space:]]/} | head -n 1) - ${branch//[[:space:]]/}"; done | sort && unset IFS

Be sure to do a git fetch --all first in order to have all public branches mirrored in your local repository.

For older versions of Git (1.9.x and earlier), the output of git branch was different, it did not print the local tracking branch after an arrow ("->").

IFS=$'\n' && for branch in $(git branch --all | grep "remotes/origin" | sort); do echo "$(git log --format=format:"%an" ${branch//[[:space:]]/} | head -n 1) - ${branch//[[:space:]]/}"; done | sort && unset IFS
Cedric Meury
  • 953
  • 1
  • 7
  • 19
  • 1
    How do we get the above command to do that but only for branches that are merged in? – J86 Jun 22 '20 at 07:57
  • @J86 That doesn't seem very straight-forward to do. Here's what I would try: I'd expand the above command to a script and incorporate the steps of this answer: https://stackoverflow.com/a/40011122/28578 – Cedric Meury Jun 24 '20 at 08:34
1

Last commit before merge has 78d9687 hash in your case. It's second in commit message. So if you to know who does it try

$ git show 78d9687
Nick Kugaevsky
  • 2,935
  • 1
  • 18
  • 22
1

You can use relative commit notation to show commits. In your example, since you merged FEATURE into STABLE, the last commit on STABLE is HEAD^1 (the first parent) and the last commit on FEATURE is HEAD^2 (the second parent).

So to show the last changes introduced by FEATURE, you would use:

git show HEAD^2

To show the one before that:

git show HEAD^2~1

And so on.

Ethan Brown
  • 26,892
  • 4
  • 80
  • 92