Recovering Local Git Mistakes with GitKraken’s One‑Click Undo
Learn how GitKraken Desktop’s one‑click Undo button uses Git’s reflog to recover local merges, resets, and branch deletions in seconds.
27 Nov 2025, 08:38 UTC

When a Local Git Mistake Feels Permanent
Imagine you have just run git reset --hard HEAD~3 on your main branch, or you merged a feature branch into the wrong target and pushed nothing yet. The commit graph looks altered, and the work you thought was safe appears to have vanished. In that moment the fear of lost hours can be real, especially if you have not backed up the changes elsewhere.
What the Undo Button Actually Does
GitKraken Desktop provides a toolbar Undo button (and a matching Redo) that reverses the most recent Git actions it has tracked in the current repository. Under the hood the button does not restore a hidden snapshot; it reads Git’s reflog—a local log that records every movement of HEAD and branch pointers—and moves the affected ref back to the previous entry. For example, after a hard reset the reflog contains an entry for the pre‑reset HEAD; Undo simply runs the equivalent of git reset --hard HEAD@{1} to bring the pointer back.
Worked Example: Merge‑then‑Undo
- Create a throwaway repository and add two commits:
mkdir undo-demo && cd undo-demo
git init
echo 'initial' > file.txt
git add file.txt
git commit -m 'initial commit'
echo 'feature work' > feature.txt
git add feature.txt
git commit -m 'feature commit'
git checkout -b feature
echo 'more' > feature.txt
git add feature.txt
git commit -m 'update feature'
- Switch back to
mainand merge the feature branch:
git checkout main
git merge feature --no-ff -m 'merge feature'
At this point git log --oneline shows the merge commit as the tip of main.
- Click the Undo button in GitKraken’s toolbar (or press the associated shortcut if you have one).
GitKraken moves the main pointer back to the commit before the merge. The merge commit disappears from the main history, but it remains reachable via the reflog.
- Verify the same result from the command line:
git reflog
# you will see an entry like: HEAD@{1}: merge feature: Fast-forward
git reset --hard HEAD@{1}
git log --oneline
The log now matches the state after step 2, confirming that the GUI Undo performed the equivalent git reset --hard operation.
Limits of the One‑Click Undo
- Local only: Undo works only on actions recorded in the repository’s reflog. It cannot affect commits that have already been pushed to a remote, because pushing creates new reflog entries on the remote side that GitKraken does not track for Undo.
- No uncommitted changes: If you have unstaged or staged but uncommitted modifications, Undo does not restore them; those changes live in the working tree or index and are not part of the reflog.
- Reflog expiration: By default Git keeps reflog entries for 90 days for reachable tips and 30 days for unreachable ones. After those periods the entries are pruned by garbage collection, making Undo impossible. Custom
gc.reflogExpireorgc.reflogExpireUnreachablesettings change this window. - Action scope: The button reverses operations that GitKraken logs—such as merges, resets, checkouts, commits, and branch deletions. It does not undo a
git push --force, a cherry‑pick that created a conflict, or changes made outside GitKraken (e.g., via the CLI) unless those actions updated the reflog.
Making Undo Work for You
To rely on the feature safely:
- Check your GitKraken Desktop version (e.g., 9.2.0) and consult the release notes for the exact list of undoable actions; the UI may evolve between releases.
- Verify reflog retention on your machine: run
git config gc.reflogExpireandgit config gc.reflogExpireUnreachable. If you need a longer window, adjust those settings in.git/config. - Remember that Undo is a convenience, not a backup. For work that must survive a push or a teammate’s fetch, use
git stashfor uncommitted changes,git revertfor published commits, or agree on a force‑push policy with your team. - When you are unsure whether an action is undoable, open the reflog (
git reflog) and see if the desired state appears as an entry; if it does, you can recover it manually even if the GUI button is greyed out.
In short, the one‑click Undo button gives you a fast, visual way to roll back recent local Git mistakes by leveraging the reflog that Git already maintains. Knowing its mechanics and its boundaries lets you treat it as a safety net rather than a guarantee.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.