threads / discuss / 46992

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

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

## tl;dr

One message between Oct 18, 2017 and Oct 18, 2017.

replies: 0people: 1as markdown or json

Robert Dailey· Oct 18, 2017, 13:57 UTC · lore

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.

← back to recent threads