Git Reflog

Vanza Setia,

Estimated reading time: 1 minute

Problem

You have done a git rebase. Then, you do not like that decision. You want to undo that.

Solution

You solve the problem with git reflog.

You have the following reflog:

2a37136 (HEAD -> main) HEAD@{0}: rebase (finish): returning to refs/heads/main
2a37136 (HEAD -> main) HEAD@{1}: rebase (pick): Make a legal page
608b1eb HEAD@{2}: rebase (fixup): Make a contact page
88c90a5 HEAD@{3}: rebase (start): checkout 70d0caa
90ca0c5 HEAD@{4}: commit: fixup! Make a contact page
edf23a5 HEAD@{5}: reset: moving to HEAD~1
d785b41 HEAD@{6}: rebase (finish): returning to refs/heads/main
d785b41 HEAD@{7}: rebase (start): checkout eecd26c
d785b41 HEAD@{8}: commit: fixup! Make a homepage
edf23a5 HEAD@{9}: commit: Make a legal page
88c90a5 HEAD@{10}: commit: Make a contact page
70d0caa HEAD@{11}: commit: Make an about page
eecd26c HEAD@{12}: commit (initial): Make a homepage

You want to go back to the state where you have not made a fixup! commit for the contact page. You also do not want to lose any local changes.

Steps:

  1. Execute git reflog to get the above output.
  2. Copy the state hash that you want to go back to.
  3. Execute git reset --mixed edf23a5.
Share your thoughts

Topic(s).

Thank you for reading this Git Reflog. You can subscribe to all my articles with the Articles RSS. If you have a positive or negative comment, please send me an email or contact me through one of my social media accounts.

Share with your network

Copy this link and send it to great people only.

https://vanzasetia.xyz/blog/git-reflog/

For you

  • Empty Links Do Not Mean Empty Brain

    I understand that we can make mistakes. I want to campaign adding an accessible name to every link should be like wearing clothes every time we go out. We can not go naked outside. We can not forget about it.

    By Vanza Setia

    a11y

  • Good Gamers Beat AI

    Developers are talking about Chat Generative Pre-trained Transformer (ChatGPT), the good and the bad things about it. But when I see it from a gamer's perspective, it is interesting.

    By Vanza Setia

    mind