Blog / git
Undo a git revert your coding agent made
Your agent reverted a commit you wanted. Drop the revert if it isn't pushed, revert the revert if it is, and re-merge a reverted branch the right way.
On this page
- Find the revert
- The revert isn't pushed yet
- The revert is pushed: revert the revert
- The agent reverted a merge
- Why merging the branch again isn't enough
- The fix
- The revert stopped on a conflict
- Revert, reset or restore?
- Stop it happening again
- Where Joxo fits
- Frequently asked questions
- How do I undo a git revert?
- Can you revert a revert in git?
- Why didn't merging the branch again bring my changes back?
- How do I find which commit a revert undid?
- How do I cancel a revert that stopped on a conflict?
- Is git revert safe on a shared branch?
- Try it with your team
You asked your agent to back out a broken test, and it ran git revert on the commit you still need. Or it reverted a whole merged branch to get the build green, and now the feature is gone from main. A revert is an ordinary commit, so undoing it is safe and quick once you know which case you're in. We ran every command with git 2.43 on a test repository.
Find the revert#
Reverts have a fixed message, so they're easy to list:
git log --oneline --grep='^Revert'5db46e4 Revert "Allow bursts of 20"The body names the commit it undid:
git log -1 --format=%b 5db46e4This reverts commit 974231b337b283d6cc5e65a497ab343b831c9c02.If the agent wrote its own message, look for it with git log --oneline -10 and check the diff with git show <sha>. A revert's diff is the exact opposite of the commit it undid.
The revert isn't pushed yet#
If the revert is the last commit on your branch and nobody else has it, drop it:
git reset --hard HEAD~1Check git status first. --hard throws away uncommitted changes in your working copy, and the agent may have left some. If it did, use git reset --keep HEAD~1 instead: it keeps those edits, and refuses to run if they're in a file the revert changed.
If other commits came after the revert, don't reset. Use the next section; it works anywhere in history.
The revert is pushed: revert the revert#
Once the revert is on a shared branch, rewriting history would break everyone who pulled it. Add a new commit that undoes it instead:
git revert --no-edit 5db46e4[main 5bc951e] Reapply "Allow bursts of 20"
1 file changed, 1 insertion(+)Git 2.43 names it "Reapply" rather than "Revert "Revert …"". The code is back exactly as it was before the agent's revert, and the history shows both steps, so a teammate reading the log sees what happened.
The agent reverted a merge#
Reverting a merge commit needs -m 1 (keep the first parent, the branch it was merged into). Without it, git refuses:
error: commit dc972a9c73c2219f13794ee16edab51fe8f73dc1 is a merge but no -m option was given.
fatal: revert failedAgents usually work that out and run git revert -m 1 <merge>. The trap comes later.
Why merging the branch again isn't enough#
Say the agent reverted the merge of agent/, then fixed the bug on that branch and merged it again. You'd expect the whole feature back. You get only the fix:
git merge --no-edit agent/search
lsapp.txt
util.txtsearch.txt is still missing. Git sees the branch's earlier commits as already merged, because they are: the revert removed their changes but not the record that they were merged. Only commits made after the revert come in.
The fix#
Revert the revert first, then merge:
git revert --no-edit 0e72897
git merge --no-edit agent/search
lsapp.txt
search.txt
util.txtNow the original work and the new fix are both on main. If you already merged the branch the wrong way, revert the revert now; it brings back what's missing either way.
The revert stopped on a conflict#
An agent reverting an older commit can hit a conflict if later commits touched the same lines:
CONFLICT (content): Merge conflict in rate.txt
error: could not revert bb832e0... Raise limitgit status then says "You are currently reverting commit bb832e0." If the agent gave up there, the repository is stuck in the middle. To back out completely:
git revert --abortYour branch returns to where it was before the revert started, with nothing committed. To finish it instead, fix the conflicted files, git add them, and run git revert --continue. Leaving a half-done revert sitting around is how conflict markers end up in a commit.
Revert, reset or restore?#
Agents mix these up, so it helps to know which one they ran:
git revert <sha>adds a new commit that undoes an old one. History is kept. Safe on shared branches.git reset <sha>moves the branch back and drops commits from it. Fine on your own branch, harmful on a shared one. If an agent reset away work, see recover work after a git reset.git restore <file>throws away uncommitted edits to a file. No commit is made, and there's no undo.
When a commit is wrong, a revert is usually the right tool. The mistake is reverting the wrong commit, or reverting a merge without planning how to bring the branch back.
Stop it happening again#
- Ask before reverting. Tell your agent in its instructions file (CLAUDE.md, AGENTS.md) to ask before running
git reverton anything it didn't write in this session. - Revert one commit, not a merge. If a merged branch broke the build, revert the single commit that broke it, or fix forward. A merge revert means you have to revert the revert before the branch can return.
- Name the commit in the message. Ask the agent to say why it reverted in the commit body. Months later, "Revert X" alone tells nobody whether X was wrong or the test was.
- Undo a merge before it's pushed with reset. If the merge only exists locally, undo the merge with a reset and skip the revert entirely.
Where Joxo fits#
When your agent and a teammate's agent work on the same project, one of them reverting the other's commit is easy to miss. In Joxo, each agent's commits show up in the project with who made them, and an agent can ask before touching a teammate's work; you answer from the desktop app or your phone. Setup is one line pasted into your agent.
Frequently asked questions#
How do I undo a git revert?#
If the revert isn't pushed and is your last commit, run git reset --hard HEAD~1. If it's pushed, run git revert on the revert commit; that brings the original change back as a new commit.
Can you revert a revert in git?#
Yes. git revert <revert-sha> makes a new commit that puts the original change back. Git 2.43 titles it "Reapply" followed by the original message.
Why didn't merging the branch again bring my changes back?#
After a merge is reverted, git still counts the branch's earlier commits as merged, so a second merge only brings in newer commits. Revert the revert first, then merge.
How do I find which commit a revert undid?#
Run git log -1 --format=%b on the revert. Its body says "This reverts commit" followed by the full hash.
How do I cancel a revert that stopped on a conflict?#
Run git revert --abort. The branch goes back to where it was before the revert started.
Is git revert safe on a shared branch?#
Yes. It adds a commit instead of removing one, so nobody who already pulled the branch has to fix their copy.