git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Problems reverting (includes reverting a merge)

From
Andreas Ericsson <ae@op5.se>
Date
Jun 9, 2008, 08:05 UTC
Message-ID
<484CE438.6040703@op5.se>
In-Reply-To
<b1d95faa0806051045t67ea0f46r55cdaeb794dc2f5c@mail.gmail.com>
jenny w wrote:
Show 22 quoted lines
> Someone made a few commits that I'm trying to revert. There are three
> commits in a row, the middle of which is a merge. There are presently
> no commits following the ones that we want to revert.
> 
> I tried git revert on the latest commit and that worked fine.
> 
> The second latest commit was a merge, so I had to use the -m switch.
> I'm not exactly sure what the parent-number refers to, so I created a
> separate branch to try things out. Since it expects I a number, I
> started from 1. That was kind of a disaster, so I deleted my branch
> and made another off of master, and then tried doing the same command
> with -m 2. This worked fine.  However ...
> 
> I then tried to revert the next commit. This said there's a conflict.
> Since there are no other commits after the ones I'm trying to revert,
> this makes me think I'm doing something wrong ... shouldn't it just be
> able to roll back?
> 
> What I'd really like to do is just zap the last 3 commits ... is there
> another way to just make things the way they were before these patches
> were applied?
> 
git diff HEAD~3 | git apply -R && git commit <relevant files>

Although that will revert all 3 of them in one go, but perhaps that's ok? Oh, and it won't work unless the merge-parent you want to revert is the "first" parent (a straight line to the left when viewed in gitk or qgit).

If you haven't published the commits anywhere yet, you can do
	git reset --hard HEAD~3
Note that this will clobber your worktree though, so use with caution.
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: jenny wNext: Alex Bennee
Message 2 of 3 in “Problems reverting (includes reverting a merge)”
  1. jenny wJun 5, 2008
  2. Andreas EricssonJun 9, 2008
  3. Alex BenneeJun 9, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.