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

Re: reverting changes

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 4, 2013, 22:19 UTC
Message-ID
<7v8v4ygcre.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACnwZYe45poRihJToDY5yrLeY-wc=6HSjZBanjGvtiopbuAAFw@mail.gmail.com>
Thiago Farina <tfransosi@gmail.com> writes:
Show 9 quoted lines
> 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.

Previous: Thiago Farina
Message 2 of 2 in “reverting changes”
  1. Thiago FarinaApr 4, 2013
  2. Junio C HamanoApr 4, 2013

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.