# this introduces a new commit (say, it's hash is 86b48ba) which removes changes, introduced in the commit in question (but those changes are still visible in the history) Git revert a8172f36 #hash of the commit you want to destroy Revert commit normally and push git checkout master In case you did push publicly (on a branch called 'master'): git checkout -b M圜ommit //save your commit in a separate branch just in case (so you don't have to dig it from reflog in case you screw up :) ) That's it, your commit changes will be in your working directory, whereas the LAST commit will be removed from your current branch. In case you have not pushed the commit publicly yet: git reset HEAD~1 -soft But any changes that are commits are recoverable even if you lose them, via the reflog, or via branch pointers or tags that you can set.There are a lot of ways to do so, for example: Type the wrong command that wipes out either or both of these and they are gone for good. The working copy and index are not commit objects and so they are not recoverable from the reflog. One reason to get your work into commits is that in git is very easy to lose the working copy or the index forever. In fact, if you have unstaged or staged changes, git prevents you from doing various useful things. The idea is to turn the representation of all your changes into separate commits, then work with the commit-munging kung-fu, and finally "de-commit" something, if necessary.įor doing complex things, git is better at working with commits than with unstaged changes or the index, which are sort of temporary areas so you want to get your work out of there and into commits first. Or else just keep the commit and work with it by doing more hacking and git commit -amend to add to it and update its message.Įverything that rebase -interactive does (and in fact, that non-interactive rebase does) can be done with cherry-pick commands, but it provides a convenient "workflow automation".įor any scenarios involving the re-ordering of commits, deletion of commits, squashing of multiple commits into one, rewriting commit messages (other than in the topmost patch) and that sort of thing, it's good to know how to use interactive rebase. At that point, I could get rid of that commit, turning it into unstaged changes: git reset HEAD^ There might be merge conflicts, which would have to be resolved, since the previously unstaged wanted changes might have depended on the staged unwanted changes.Īt the end, I would have a single commit which has just the changes that were previously unstaged, and the unwanted changes are gone. In the editor window that comes up, I would simply delete the commit which holds the unwanted changes that came from the unwanted index, and then save and quit, letting the interactive rebase do the rest. Git rebase -interactive HEAD^^ # rebase top two commits onto same branch Git commit -a # commit the remaining changes In that case, what I would do would be to use interactive rebase to splice the changes out: git commit # commit the index The end effect is exactly like squirreling away the results of git diff HEAD, rolling everything back to the topmost commit, and then re-applying that diff to HEAD to re-create the original work tree.īut suppose you want to throw away the changes from the index such that these discarded changes are actually subtracted from your work. This is equivalent to your self answer, "using git commands only". To discard the index without touching the working tree, you can just do this: git reset
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |