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

Re: Revert a single commit in a single file

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 25, 2011, 19:43 UTC
Message-ID
<AANLkTinzhd_nL265e7DZA4xEnXqDn-5m=9GPS7JsFY-S@mail.gmail.com>
In-Reply-To
<7v8vx4aqun.fsf@alter.siamese.dyndns.org>
On Fri, Feb 25, 2011 at 19:53, Junio C Hamano <gitster@pobox.com> wrote:
Show 27 quoted lines
> Thomas Ferris Nicolaisen <tfnico@gmail.com> writes:
>
>> 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?
>
> I am afraid that it would lead to encouraging people to record a horribly
> broken history, unless you think carefully about what the resulting commit
> log message should describe.  It would look _as if_ you negated the effect
> of the original commit as a whole, but in reality you are only reverting
> just a part of what you chose to revert with <path>.
>
> We do encourage people to record the _reason_ why the particular commit
> was removed by not supporting "-m <message>" option to "git revert"
> command, but the commit template in the editor given to the user should
> make it absolutely clear that the particular partial revert is reverting
> only a part of the original commit, and need additional words to strongly
> encourage to record why only that part and not other parts are reverted.

Agreed, but FWIW where I work I've seen people record "horribly broken history" already because git-revert doesn't support this, and they don't know the trick I described.

I also don't agree that the history would be horribly broken. The message is just an advisory template, it's always the content that changed that we care about, and we can analyze the history and see that this chunk is the reverse of a chunk in a previous commit.

But just like we now have:
    Revert "some commit"
    This partially reverts commit <sha1>.
We could have with <path>:
    Revert "some commit"
    This partially reverts commit <sha1>. Only the path <path> has
    been reverted, which is X out of Y files changed in the original
    commit.
Or something like that.
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 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.