-
Notifications
You must be signed in to change notification settings - Fork 133
git tricks
mandd edited this page May 19, 2017
·
2 revisions
You may need to do a bit of digging to find the correct commit, but this handy command will list all of the commits labeled as merges that date back to when a commit was created:
git log <SHA-1 for commit of interest>..devel --ancestry-path --merges
Typically, the merge request commit should look something like:
commit <hash>
Merge: <branch commit> <devel head at time of commit>
Author: Somebody different than the author of the commit
Date: XXXX
Merge branch 'xx/xxx' into 'devel'
Merge request name
Merge description
See merge request !447
So, with this in mind, we can pipe the entire output to awk and let it grab the last occurence of the informative line "Merge branch ..." Since this part of a commit's log is programmatically written, we can pattern match it with a reasonable level of confidence:
git log <SHA-1 for commit of interest>..devel --ancestry-path --merges | awk '/Merge branch / {a=$0} END{print a}'
Alternatively, if you are more of a grep person, you can do the same thing, just pipe it to tail to get the last item (or don't if you want to see all of the subsequent merges it belongs to):
git log <SHA-1 for commit of interest>..devel --ancestry-path --merges | grep 'Merge branch' | tail -n 1
git reset --merge