mat
mat

Reputation: 1717

Find out commit id of branch before I pulled

I am working in a git repository on the master branch. Recently I have pulled from a remote to update the branch. Is there some way to find out, which commit-ID was the HEAD of master before I pulled?

Upvotes: 4

Views: 3318

Answers (3)

mat
mat

Reputation: 1717

git reflog solved my problem, as suggested in a comment by @ElpieKay

Upvotes: 2

junvar
junvar

Reputation: 11604

In the simple cases where you've not changed your branch after the pull, you could use the master@{1} or main@{1} reference, e.g. git log -1 master@{1}.

Upvotes: 0

Claudius B
Claudius B

Reputation: 86

If you didn't merge anything after the pull you can use

git log -1 --merges

This will print the latest merge commit with format

commit <merge-commit-hash>
Merge: <first-parent-hash> <second-parent-hash> ...
Author: ...
Date: ...

The second line (the one that starts with "Merge") lists the parents of that merge commit. The first one (<first-parent-hash>) is the hash of the commit HEAD was pointing to before you merged.

In other words, you had <first-parent-hash> checked out when you typed git pull.

EDIT Limitation: As jacob-krall pointed out, this won't show you where HEAD was if the merge (that was performed as part of the pull) resolved as a fast-forward since such merges don't create commit objects.

Upvotes: 1

Related Questions