Perhaps you forgot to stage a file in the last commit, or had a typo in the commit message, or even made mistakes in the code, but you have not yet committed anything else on top of it. In many cases, you catch your mistake right after you complete a commit. However, because of the freedom you have with targeting any commit, you can more easily introduce a conflict when attempting a Git revert. The most common scenario for reverting a Git commit is that you’ve accidentally committed something and it was merged into a shared branch or repo that your teammates work from Git revert can be particularly useful when you publish to and work off shared branches.Īnother advantage is that the commit you target can be arbitrary you can target any commit at any point in history. Importantly, this means that the existing commit history prior to the newly added “undo” commit, including the original error commit, is preserved. The git revert command follows this principle: it introduces a new commit to the commit history whose sole purpose is to undo the changes of a targeted commit. In other words, rather than going back in time, we can introduce an “equal but opposite” action to neutralize the effect of our original action. The philosophy behind Git revert is that we can undo past mistakes with “forward change”.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |