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

Multiple ways to undo changes to a file in the tip commit

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Oct 18, 2017, 13:57 UTC
Message-ID
<CAHd499BYsDwHRttBKxSbJS452-+VYPLnJ38z5yyHv=KkvHV0UA@mail.gmail.com>

Suppose the tip commit of my branch contains changes to multiple files. If I want to revert all changes in one file from that commit, I have two options that I know of:

$ git reset @^ -- foo.txt $ git commit --amend --no-edit $ git checkout -- foo.txt

Or:

$ git checkout @^ -- foo.txt $ git commit --amend --no-edit

For simpler steps, I normally use the latter option. However, is there value in the former option (using reset)? When would you use one or the other?

Disclaimer: I just typed up the above commands, I might have some
details wrong, but hopefully you get the gist of it.
Thanks in advance.
Message 1 of 1 in “Multiple ways to undo changes to a file in the tip commit”
  1. Robert DaileyOct 18, 2017

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.