how to find the git history of a remote branch after reset?

Viewed 555

I have mistakenly reset the remote branch (not reverted).

  # git reset #hash
    # git push origin develop

I would like to check the latest commits made to that branch

How can i get all logs/history of that remote branch? (my local branch also uptodate with remote, so i couldn't see any changes there)

If I do;

# git log origin/develop
# git log develop

I could get logs upto reset point. Not after that.:(

2 Answers

You can use git reflog command to find out at which commit (hash) the develop reference pointed before the reset, and use this hash as needed - create a new branch from it, reset develop back and restore pre-reset state, or just browse git log for that hash, depending on the needs. Then push the change again, to restore the state on the server as well.

When you change a reference, which is what you do when you commit to a branch or reset it to a different commit, you can access prior values of that reference using the <refname>@{<n>} format.

In your case, you should be able to see git log develop@{1} to see the log from the last tip of the develop branch.

The same is true for origin/develop@{1}, but "prior values" here won't necessarily include all changes, e.g. if a branch was committed to by someone else multiple times between your own git fetch commands.

In general, you can use git reflog to see changes to references, which will hopefully have a line like this near the top:

1234567 (HEAD -> develop) HEAD@{0}: reset: moving to 1234567abcde

Prior to that will be previous values of references of any branches you've checked out or committed to. You can use that to decide what to do next.

Related