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, 12:37 UTC
Message-ID
<4D67A293.2050306@drmicha.warpmail.net>
In-Reply-To
<AANLkTimLRc4LybUvmD2ZCKfQqEP+vr+2aBnb4n3B+Mb2@mail.gmail.com>
Ævar Arnfjörð Bjarmason venit, vidit, dixit 25.02.2011 12:17:
Show 18 quoted lines
> On Fri, Feb 25, 2011 at 11:34, Thomas Ferris Nicolaisen
> <tfnico@gmail.com> wrote:
>> I tried asking the same question on the "newbie" list some time ago:
>>
>> http://groups.google.com/group/git-users/browse_thread/thread/d562b4eeac016711
>>
>> Basically, when I go
>>> git revert <commit> <path>
>>
>> .. my expectation was that a new commit would be made reverting the
>> changes from the old commit, but only for specified path/file.
>>
>> Maybe it's a bit of a corner-case, but still would be nice to have
>> once in a while. What do you think?
> 
> It would. What you can do in the meantime is:
> 
>     git revert <commit>

Ævar meant to write "git revert --no-commit <commit>" here. (Or there wouldn't be anything to reset and add.)

>     git reset
>     git add <path>
>     git commit ...
>     git reset --hard # making sure you didn't have uncommited changes earlier

If you want to revert changes to all files but a few, you can do it the other way round (revert, checkout HEAD^ -- <path>, commit --amend).

Cheers, Michael

Previous: Ævar Arnfjörð BjarmasonNext: Dario Rodriguez
Message 3 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.