I have two branches (development and main). From time to time the development branch gets merged into the main branch.
So there are merge commits like Merge branch 'development' into 'main'.
Now I do need the commit hash from the last development commit, which leads to the merge commit - not the merge commit itself, which is on the master branch. Is that possible?
Doing something like git log --merges origin/master --oneline --grep='^Merge branch development into main' -1 gives me the merge commit on the master branch, but I need the commit before this one (on the development branch).
CodePudding user response:
Since you have the merge commit, you can do a:
git log <mergeCommit>^2 -1
That would give you the last development commit leading to that merge.
It uses the git rev-parse <rev>^[<n>] notation
In a bash session
git log -1 \
$(git log --merges origin/master --format=format:%H --grep='^Merge branch development into main' -1)^2
