How to undo a git rebase? Hint: git reflog and git reset —…
    Neura MarketNeura Market/Stable Diffusion
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityStable DiffusionStable Diffusion
    DeepSeekDeepSeekCoPilotCoPilotMidjourneyMidjourney
    View All Directories
    OverviewPromptsBlogVideosGuidesCoursesCommunityModelsLoRAsComfyUI WorkflowsTrending
    Stable DiffusionBlogHow to undo a git rebase? Hint: git reflog and git reset
    Back to Blog
    How to undo a git rebase? Hint: git reflog and git reset
    beginners

    How to undo a git rebase? Hint: git reflog and git reset

    Gunnari Auvinen June 7, 2026
    0 views

    The other day at work a group of us were asked if any of us were Git masters, at which point my ears...

    The other day at work a group of us were asked if any of us were Git masters, at which point my ears perked up and I asked him to explain what exactly he needed help with at that moment. He then told me that a teammate had lost roughly a half-days worth of work after a bad git rebase and he wanted to know if it was possible to recover their lost work. Now while I'm not a Git master, I vaguely remembered something from a lecture and told him that I would look into it and get back to him in a few minutes.

    After a couple of minutes of searching I managed to find the information that I was searching for to "save the day." What I had discovered was that Git keeps track of the tips of branches and when they're changed and this information can be accessed via the git reflog command. In this case the git reflog command allowed us to find the reference to the commit that had been made prior to the bad git rebase. The reflog had the various messages associated with the branch tip changes and in our case we looked for the last commit message that had been entered prior to the rebase, which had a reference similar to HEAD@{7}. Having this reference allowed us to use the git reset --hard HEAD@{7} command to go back to that specific commit. With a little bit of searching we fortunately saved hours worth of work!

    As this concept can be a little bit nebulous in just text I've provided an example below to help flush things out.

    Example of How to Undo a git rebase

    For this example I made a little git repository that uses master and the amazing-feature branch for us. Here is a printout of a git log --oneline command before the git rebase is done, while in the amazing-feature branch.

    98008d5 Add the divide function to amazing-feature.
    93c18de Add multiply function to amazing-feature.
    abdc941 Add amazing-feature.
    18244f8 Add the add function to first-feature.
    3a01fc1 Add the amazing first-feature.
    

    Next I did:

    ➜  git-reflog-git-rebase-example git:(amazing-feature) git rebase master
    

    First, rewinding head to replay your work on top of it...

    Applying: Add amazing-feature.
    Applying: Add multiply function to amazing-feature.
    Applying: Add the divide function to amazing-feature.
    ➜  git-reflog-git-rebase-example git:(amazing-feature)
    

    This added the other commits from master that this branch didn't have. Following that I did a git log --oneline.

    b13c3f1 Add the divide function to amazing-feature.
    4fdbc95 Add multiply function to amazing-feature.
    085c6a5 Add amazing-feature.
    2c0a30c Add the square function to best-feature file.
    18244f8 Add the add function to first-feature.
    3a01fc1 Add the amazing first-feature.
    

    Oh no, we don't actually want that information from master merged into the amazing-feature branch! We need to figure out a way to undo that rebase. Fortunately we can look up the HEAD reference that we want to go to by using the git reflog command.

    b13c3f1 HEAD@{0}: rebase finished: returning to refs/heads/amazing-feature
    b13c3f1 HEAD@{1}: rebase: Add the divide function to amazing-feature.
    4fdbc95 HEAD@{2}: rebase: Add multiply function to amazing-feature.
    085c6a5 HEAD@{3}: rebase: Add amazing-feature.
    2c0a30c HEAD@{4}: rebase: checkout master
    98008d5 HEAD@{5}: commit: Add the divide function to amazing-feature.
    93c18de HEAD@{6}: checkout: moving from master to amazing-feature
    2c0a30c HEAD@{7}: commit: Add the square function to best-feature file.
    18244f8 HEAD@{8}: checkout: moving from amazing-feature to master
    93c18de HEAD@{9}: commit: Add multiply function to amazing-feature.
    abdc941 HEAD@{10}: commit: Add amazing-feature.
    18244f8 HEAD@{11}: checkout: moving from master to amazing-feature
    18244f8 HEAD@{12}: commit: Add the add function to first-feature.
    3a01fc1 HEAD@{13}: commit (initial): Add the amazing first-feature.
    

    Looking at the reflog printout, I know that to undo the git rebase that I need to go to the reference HEAD@{5} when I do a git reset, as that reference is the last time the HEAD pointed to the proper place.

    ➜  git-reflog-git-rebase-example git:(amazing-feature) git reset --hard HEAD@{5}
    HEAD is now at 98008d5 Add the divide function to amazing-feature.
    ➜  git-reflog-git-rebase-example git:(amazing-feature)
    

    One last git log --oneline to make sure that the rebase has been undone.

    98008d5 Add the divide function to amazing-feature.
    93c18de Add multiply function to amazing-feature.
    abdc941 Add amazing-feature.
    18244f8 Add the add function to first-feature.
    3a01fc1 Add the amazing first-feature.
    

    Phew it has been fixed! Here's what git reflog shows after the git reset command from immediately prior.

    98008d5 HEAD@{0}: reset: moving to HEAD@{5}
    b13c3f1 HEAD@{1}: rebase finished: returning to refs/heads/amazing-feature
    b13c3f1 HEAD@{2}: rebase: Add the divide function to amazing-feature.
    4fdbc95 HEAD@{3}: rebase: Add multiply function to amazing-feature.
    085c6a5 HEAD@{4}: rebase: Add amazing-feature.
    2c0a30c HEAD@{5}: rebase: checkout master
    98008d5 HEAD@{6}: commit: Add the divide function to amazing-feature.
    93c18de HEAD@{7}: checkout: moving from master to amazing-feature
    2c0a30c HEAD@{8}: commit: Add the square function to best-feature file.
    18244f8 HEAD@{9}: checkout: moving from amazing-feature to master
    93c18de HEAD@{10}: commit: Add multiply function to amazing-feature.
    abdc941 HEAD@{11}: commit: Add amazing-feature.
    18244f8 HEAD@{12}: checkout: moving from master to amazing-feature
    18244f8 HEAD@{13}: commit: Add the add function to first-feature.
    3a01fc1 HEAD@{14}: commit (initial): Add the amazing first-feature.
    

    As you can see, the reflog shows the HEAD pointer moves back to the reference that was at HEAD@{5} and is now at HEAD@{6} in the last reflog printout.

    Always Push to Your Remote Prior to a git rebase

    While I was able to find a solution to the student's problem and we were able to save a half-days worth of work, there is an additional takeaway from this experience. My recommendation is that prior to performing a git rebase always push your work up to a remote if you haven't already. This way even if your git local git history gets messed up, you can always just clone down the remote again.

    It really is great to know that you can go back in time and fix those seemingly unfixable mistakes with a few key strokes!

    Tags

    beginnersgitproductivitytutorial

    Comments

    More Blog

    View all
    Context bankruptcy: The case for strategic forgetting for AI Agentsai

    Context bankruptcy: The case for strategic forgetting for AI Agents

    Most of us have seen a coding agent fail to complete a task we know it can do. We just don't...

    J
    James O'Reilly
    Parallel Compliance Engine: Drive-to-Sheets Multi-Agent Orchestrationgooglecloud

    Parallel Compliance Engine: Drive-to-Sheets Multi-Agent Orchestration

    When building Generative AI applications, developers often encounter a massive bottleneck: sequential...

    A
    Aryan Irani
    Is It Ethical to Post and Ask About Circuits on Dev.to?discuss

    Is It Ethical to Post and Ask About Circuits on Dev.to?

    I’ve been thinking about sharing some electronic circuit posts on Dev.to — small circuits, DIY...

    C
    codebunny20
    The One-Click Exporter: AI Studio Antigravity, Probed to Its Limitsagents

    The One-Click Exporter: AI Studio Antigravity, Probed to Its Limits

    What nobody tells you about exporting your multi-agent prototype to a local workspace. Every...

    L
    leslysandra
    Guarding the till while autonomous data agents do the diggingagenticarchitect

    Guarding the till while autonomous data agents do the digging

    Autonomous agents are genuinely good at answering messy business questions. Give one an LLM and a set...

    S
    Sireesha Pulipati
    Return on Attention: Why AI Code Reviews Are Wearing Us Outai

    Return on Attention: Why AI Code Reviews Are Wearing Us Out

    PR volume went up, ticket quality didn't, and the gap got filled with LLMs on both sides of the review: bots reviewing, bots replying, bots occasionally arguing with bots about priorities that only existed in a teammate's head. Our CEO named the actual problem, and it's bigger than code review.

    C
    christine

    Stay up to date

    Get the latest Stable Diffusion prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Stable Diffusion and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.