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

Re: Revert a single commit in a single file

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 25, 2011, 13:05 UTC
Message-ID
<4D67A92D.2000300@drmicha.warpmail.net>
In-Reply-To
<AANLkTimqszvGjVeJHKLPWicDugeOuqbgO1+wy5BO-AE0@mail.gmail.com>
Dario Rodriguez venit, vidit, dixit 25.02.2011 13:48:
> The most sensible way to do this seems to be:
To do what? I you hadn't top posted we would know what "this" referred to.
>  git checkout HEAD~2 file.c
> 
> And your index will show file.c modified, as it will have it's content
> reverted 2 commits.

It will have its content reset to what it was in HEAD~2. This is very different from reverting the change made in HEAD~2:

> The behavior of 'revert' is to revert commits, not files, so it's not
> expected to work if you say 'git revert <commit> <path>'
It makes perfect sense, it's just not implemented.
Note that you can also
git show <commit> -- <path> | git apply -R
to achieve a partial revert. That might be the easiest route to take.
Michael
[Cutting the bottom copy - what is it good for there?]
Previous: Dario RodriguezNext: Thomas Ferris Nicolaisen
Message 5 of 13 in “Revert a single commit in a single file”
  1. Thomas Ferris NicolaisenFeb 25, 2011
  2. Ævar Arnfjörð BjarmasonFeb 25, 2011
  3. Michael J GruberFeb 25, 2011
  4. Dario RodriguezFeb 25, 2011
  5. Michael J GruberFeb 25, 2011
  6. Thomas Ferris NicolaisenFeb 25, 2011
  7. Dario RodriguezFeb 25, 2011
  8. Junio C HamanoFeb 25, 2011
  9. Ævar Arnfjörð BjarmasonFeb 25, 2011
  10. Junio C HamanoFeb 25, 2011
  11. Ævar Arnfjörð BjarmasonFeb 25, 2011
  12. Jay SoffianFeb 25, 2011
  13. Dario RodriguezFeb 26, 2011

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.