git: see the parent commit of a squash merge

Viewed 445

lets say I have the following graph

master  A------D
         \
feature   B--C----E

If D is a squash-merge of feature at commit C, but then a new commit (E) is pushed to feature, there is no obvious link between commit D and the exact commit that was merged into master.

My question is whether it is possible to retrieve this link. Is there a git command that can be run that will, for a squash-merge, return the commit hash of the exact commit that was squashed in?

NOTE: The commit message was changed in my repo, so the fact that by default git will record the commit hashes that are squashed in the message is not useful

2 Answers

You told Git not to record the merge, and then erased its offered note-to-self about not having recorded it. That's it, you've found all of Git's records of the merge and told it to destroy them.

As @jthill answered : the actions you described deleted the links you had between the squashed commit and the original commit.

As a last resort, if the commits' content were not changed, you can search for commits having the same tree :

# one way to view the tree hash : have "git log" print it

# look at the tree for commit A :
$ git log --pretty="commit:%h tree:%t - %s" -1 <A>
commit:42bda4632 tree:07f4df9d1 - squashed commit

# look for a commit with same tree in history of E :
$ git log --pretty="commit:%h tree:%t - %s" <E> | grep "tree:07f4df9d1"
# hopefully, you will get commit C :
commit:7dd1982a4 tree:07f4df9d1 - commit with rewritten message
Related