Skip to content

Instantly share code, notes, and snippets.

@zadr
Last active September 26, 2016 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zadr/c6a534027956e176f1fa945dda33da84 to your computer and use it in GitHub Desktop.
Save zadr/c6a534027956e176f1fa945dda33da84 to your computer and use it in GitHub Desktop.
find the parent of merge commits to have manual branch-aware bisecting
git log master..HEAD --merges --format="%h" | tr '\n' '\0' | xargs -0 -n1 git rev-list --parents -n 1 | awk '{print $(NF)}' | tr '\n' '\0' | xargs -0 -n1 git log --pretty=oneline -n 1
# find all merges, and only print out the hash of the commit
git log master..HEAD --merges --format="%h"
# translate all \n's into \0's for `xargs`
# with gnu xargs, you can get rid of this command and pass in `-d '\n'` instead of having to convert and pass in `-0` to xargs
tr '\n' '\0'
# for every merge commit, find the most recent parents that were responsible for the merge
xargs -0 -n1 git rev-list --parents -n 1
# get the last column, which is the hash of the parent on the branch being merged in
awk '{print $(NF)}'
# technially we could stop here, since we have a list of the last commit of each branch before it was merged in
# but lets keep going to get better output
# translate all \n's into \0's for `xargs` (again, since we have one more commit)
tr '\n' '\0'
# get a git log of each commit, in the format of '#{hash} #{commit message}'
xargs -0 -n1 git log --pretty=oneline -n 1
given:
------feature-x--bugfix-y--bugfix-z
/ / /
---C1 / /
--------C2 /
-----C3----------------C4
this command finds and prints:
#{C1-hash} #{C1-commit message}
#{C2-hash} #{C2-commit message}
#{C4-hash} #{C4-commit message}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment