How to undo a git rebase? Hint: git reflog and git reset — CoPilot Blog
    Neura MarketNeura Market/CoPilot
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityCoPilotCoPilot
    DeepSeekDeepSeekStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsBlogVideosGuidesCoursesCommunityPluginsTrendingGenerate
    CoPilotBlogHow 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. ```bash 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: ```bash ➜ git-reflog-git-rebase-example git:(amazing-feature) git rebase master ``` First, rewinding head to replay your work on top of it... ```bash 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`. ```bash 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. ```bash 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. ```bash ➜ 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. ```bash 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. ```bash 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
    Minimalist EKS: The Easy Waykubernetes

    Minimalist EKS: The Easy Way

    Amazon EKS manages the Kubernetes control plane, but you remain responsible for provisioning the...

    J
    Joaquin Menchaca
    Never forget to enter the Stern Grove lottery again!ai

    Never forget to enter the Stern Grove lottery again!

    Browser automation with Playwright, Python, GitHub Actions, and Entire to auto-enter San Francisco Stern Grove concert lotteries each week!

    L
    Lizzie Siegle
    A Free Screenshot Editor That Never Uploads Your Imagetypescript

    A Free Screenshot Editor That Never Uploads Your Image

    A free screenshot and image editor that runs entirely in your browser. Keeping every edit reversible and handling big phone photos, in plain TypeScript and Canvas2D.

    M
    Martin Stark
    I built a CLI to break my highlights out of Apple Booksshowdev

    I built a CLI to break my highlights out of Apple Books

    A macOS CLI + MCP server that exports Apple Books highlights to Markdown and gives AI assistants direct access to your reading notes.

    A
    Andrey Korchak
    A Developer's Guide to Agent Hooks in Antigravity CLIai

    A Developer's Guide to Agent Hooks in Antigravity CLI

    Motivation To be quite honest, "Hooks"—the shell commands we trigger at specific points...

    T
    Tanaike
    Tactical vs. Strategic Agentic AI Development — A Playbook for Developersagents

    Tactical vs. Strategic Agentic AI Development — A Playbook for Developers

    The Strategic Engineer: Why Writing Code Is No Longer Your Most Valuable Skill ...

    A
    Adewumi Saheed Adewale

    Stay up to date

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

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for CoPilot 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.