Undoing git actions
Guido Ostkamp
3 posts
|
Hello, I would like to know whether undoing Git actions is covered in full detail in the book. git add I had a hard time with the ‘git revert’ stuff as it doesn’t seem to work as a beginner would expect or you may need other or even a sequence of commands to undo a change. In my view, this topic strongly belongs to “Everyday” Git actions. Thanks for your information. Regards Guido |
Travis Swice...
13 posts
|
Hey Guido; Was loading this page when I say an email come in. I hope you don’t mind me just responding here – that way everyone can see it. Yes, the book does deal with undoing changing. In good Git form, it covers a few different methods of undoing and removing changes, including (off of the top of my head):
I hope that answers your question. -T |
Guido Ostkamp
3 posts
|
Hi Travis, thanks for your reply. I bought the beta to have a closer look at this. While the writeup regarding the dangers of rewriting history is ok I I give you some examples: Most people will never do any partial staging as Git allows. They want just to I give you some example cases: Change existing file: $ edit somefile$ git add somefile $ git status
To undo this you need two steps: $ git reset HEAD somefile The second step only, if you not only want to unstage but want to completely get rid of the changes, of course. If you remove a file: $ git rm somefile$ git status
$ git reset HEAD somefile Here the second step is required, otherwise the file would not be recovered. For moving it even gets more complicated: $ git mv file1 file2$ git status
$ git reset file2 ... and I don’t know how complicated it will get to recover a move of an entire directory with multiple files. I omit the adding of a new file example which also needs to be covered. Regarding undoing it should be mentioned that “git checkout” undoes local changes that are not yet staged – without a warning! $ edit somefile Oops, all changes lost! I suggest to add such examples to the book including what happened and why. Best regards Guido |
Guido Ostkamp
3 posts
|
Hi again Travis, just wanted to inform you that I’ve created an erratum entry for this topic as well. |
David James
1 post
|
Guido, thanks for sharing that. I only use `git checkout` to switch branches. Looking at the man page just now made me realize that it can be used to update “the named paths in the working tree from the index file” as well—which indeed can destroy unstaged changes. |
5 posts, 3 voices
