?

Log in

January 5th, 2009


Previous Entry Share Next Entry
06:20 pm - How do I cancel what I did...
There are three kinds of cancelling in the git workflow:
  1. A change recorded by an earlier commit is not appropriate, even though it might have made sense in the past, and I'd like to record a new commit that reverses the effects of such a commit;
  2. I asked git earlier to record the state of this path back then in the next commit, but I changed my mind;
  3. I edited this file in my work tree and created a mess, and I'd like to bring it back to the last known good state.

The first one is "git revert $commit".  This is used to record a new commit that reverses the effects of the reverted commit, and it asks you to record why the change the reverted one brought in is not appropriate anymore.

The second one is "git reset $path".  It can be used after you did "git add $path" (either because you thought you modified it to some reasonable shape and wanted to record that contents, or because you created that file and are telling git about it for the first time).

The third one can be restated as "I'd like to check out a good copy of it from the index", which is "git checkout $path", or "I'd like to check out a good copy of it from the last commit", which is "git checkout HEAD $path".

Alternatively, you can even erase the fact that you made a mistake in the past out of the history, but that will be a separate topic.


 



Tags:

(Leave a comment)

How do I cancel what I did... - gitster's journal

> Recent Entries
> Archive
> Friends
> Profile

Links
Pages at the k.org
Gifts
貢ぎ物
The latest blog by Gitster

> Go to Top
LiveJournal.com