couturesilikon.blogg.se

Git revert commit
Git revert commit





git revert commit

With the -hard option, it replaces the contents of your working directory with what was on. If you want to set your branch to the state of a particular commit (as implied by the OP), you can use git reset, or git reset -hard The first option only updates the INDEX, leaving files in your working directory unchanged as if you had made the edits but not yet committed them. It's more or less a way to 'undo' a commit and save that undo in your history as a new commit. Hopefully soon I’ll have some better posts up regarding these kinds of situations.The above answer is not quite correct - git revert does not set your repository to that commit - git revert creates a new commit that undoes the changes introduced by commit. The Git documentation suggests that you look at this message from Linus if you need some help resolving merges. The default commit message shows the commit that was reverted as well. It’s just a matter of figuring out which commit you need to roll back. Using -m 2 will revert the second commit ( 62db4af). Let’s look at the merge commit shown above:Ĭommit 137ea95c911633d3e908f6906e3adf6372cfb0adīasically, if we do git revert HEAD~1 -m 1, you’ll get the first commit in the merge reverted ( 5f576a9). This requires a number argument, which is a bit misleading. By using the -m or -mainline option, you can pick out which commit should be part of the ‘mainline’.

git revert commit

With merges, you need to pick one of the merged in commits to revert. You may receive this message when trying to revert one:įatal: Commit 137ea95 is a merge but no -m option was given. If you need to edit files further to complete the revert or possibly revert more than one commit, try out this option.įinally, dealing with reverting merges is somewhat irksome. This will simply leave the reverted changes in your working directory and not automatically commit them. Use this to explain why the changes are being backed out! If for some reason you don’t want to edit the commit message, tacking on -no-edit will allow you do so.Īnother helpful option is the -n or -no-commit flag. Of course, if the commit that you want to revert doesn’t apply cleanly you’re going to have to manually resolve the merge.īy default using this command will bring up your $EDITOR so you can modify the commit message of the revert. You can also pass in any SHA for any commit to revert those changes. "Revert "Updated to Rails 2.3.2 and edge hoptoad_notifier"" So, you wanted to revert the last commit you just made on your current branch: The “revert” command works like so: it basically reverses whatever changes made in the commit passed in by creating a new commit. Luckily, git revert is just the scalpel you need to extract that bad commit. Somehow though, that bug got into the repository, and now you need to get it out. Perhaps you didn’t have enough coffee that morning, or it was just before lunch.







Git revert commit