git sha prior to merge
·237 words·2 mins
Get the SHA for the commit immediately prior to merge #
If you want to get the last SHA for the branch that merges to a branch, you can run the following:
| |
This works because (from chat GPT), the simpler command
| |
The git log
^2 -1 command is used to display information about the second parent of a merge commit. Let’s break down the command:
- git log: This command is used to display commit logs.
- <mergeCommit>: This is the SHA of the merge commit you’re interested in.
- ^2: This syntax specifies the second parent of the merge commit. In Git, merge commits typically have multiple parents, with the first parent being the branch into which the changes were merged, and the second parent being the branch from which the changes were merged.
-1: This option limits the output to just one commit.
So, git log^2 -1 will show information about the commit that was merged into the branch along with the specified merge commit. This is particularly useful when you want to see the commit that was merged, especially in cases where the merge commit doesn’t contain the changes directly but rather merges them from another branch. The output of the first command is the last SHA of the branch that was merged into the branch pointed to by HEAD.