3

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.:(

3
  • If your local branch and the remote branch are the same, then git log develop and git log origin/develop are going to be identical.
    – cmbuckley
    Commented Mar 11, 2020 at 23:18
  • @cmbuckley Yes, it shows only at that point where i reset. not the commits i made after. I would like to see those after from the rest point
    – Ratha
    Commented Mar 11, 2020 at 23:22
  • What I mean is that your origin is not going to help in this scenario. Assuming you've made no more changes/commits to that branch, then git log develop@{1} is probably where you should start. See <refname>@{<n>} in the git documentation.
    – cmbuckley
    Commented Mar 11, 2020 at 23:31

2 Answers 2

2

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.

5
  • I have tried this # git reflog origin develop@{0} it gives //f47299b (HEAD -> develop, origin/develop) develop@{0}: commit: updated common flows version 508db3f develop@{1}: reset: moving to 508db3f06254020828a622a5a518c08c1ecd2e81 a8f026d develop@{2}: commit: adding mock url 6c4e4e4 develop@{3}: pull: Fast-forward 8ac3ef2 develop@{4}: commit: adding dummy payload 5cf5346 develop@{5}: commit: adding dummy payload//
    – Ratha
    Commented Mar 11, 2020 at 23:45
  • In the above i want to see waht happened i this,// 6c4e4e4 develop@{3}: pull: Fast-forward // How can i find code changes there?
    – Ratha
    Commented Mar 11, 2020 at 23:46
  • Once you know a hash like that, you can just do something like git show 6c4e4e4 or git log -p 6c4e4e4 to see what's going on.
    – cmbuckley
    Commented Mar 11, 2020 at 23:48
  • Thanks a lot..thats what i needed..great
    – Ratha
    Commented Mar 11, 2020 at 23:49
  • git log develop@{1} was very useful for trouble-shooting after I used git branch -f to point a branch to a different commit. (Long story that involved the main branch of a repo in codecommit.) git reflog strikes me as un-intuitive -- I had no idea how to grok the results of that command. Commented Jun 8, 2023 at 20:49
1

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.

1
  • it gives full log git reflog origin develop@{0} . Now how should i see files changed at this commit? //6c4e4e4 develop@{3}: pull: Fast-forward// I got it, git show 6c4e4e4 is the one i needed.Thanks
    – Ratha
    Commented Mar 11, 2020 at 23:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.