Thread (1 message) 1 message, 1 author, 2016-06-15
  • (off-list ancestor, not in this archive)
  • Re: reverting changes · Junio C Hamano <hidden> · 2016-06-15

Re: reverting changes

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:41

Thiago Farina [off-list ref] writes:
When I want to revert a change to a file that is already committed
what is the best way?

The way I found was:

$ git checkout HEAD /path/to/my/file
$ git reset HEAD /path/to/my/file

Is this the canonical/best way or there other (easier-faster) ways?
If the issue you are solving is:

  What I committed to path/to/my/file is in good state.  I then
  edited path/to/my/file but it turns out that I do not like what I
  did.  I want the version I committed back (perhaps to start over,
  perhaps to do nothing further).

then you can checkout the path out of the commit, i.e.

	git checkout HEAD path/to/my/file

is the canonical and best way.

But I am not sure if that is what you are asking with "want to
revert a change to a file that is already commited".  It can be
read:

    I started from one state, made changes and have already
    committed them.  These changes were bad ones that I regret, and
    I do not want them.

and if so, "git checkout HEAD path/to/my/file" will happily grab the
state after these bad changes are applied out of the commit.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help