$ git revert -no-editĬreating a new revert commit is the default behavior of the Git Revert command. The autogenerated message is of the format - Revert "Commit Message of the Unwanted Commit". We can skip this step and let Git autogenerate a message for our commit by using the -no-edit command. $ git revert īy default, the above command will open our configured text editor where we can alter the message of the new revert commit that will be created. We just need to mention the hash of the commit that we want to undo and the rest is handled by Git Revert. The Git Revert command is fairly easy to use. Essentially, Git Reset can only undo in a straight-line path and cannot jump commits in between. But with Git Reset we will first have to continuously undo the commits up to that one unwanted commit and then reapply the changes of all the other commits. Another advantage of Git Revert over Git Reset is that we can directly pick any commit from the history and undo it.We can still forcefully push the changes but this will lead to inconsistencies for other developers. If we alter the commit history of a branch and try to push it to a remote repository, then Git will block that push. This approach can be very helpful when working on shared branches or when pushing to a remote repository. This way our project history is unmodified and, we have also removed the effects of the unwanted commit.Instead of rewriting the history of our project, it will simply create a new commit that has the inverse of all the changes of the commit that we want to undo.One may wonder that the Git Reset command does the same thing and why use Git Revert? The difference is that Git Revert will undo a commit in a forward-moving fashion. As discussed above, the Git Revert command is used to undo commits.Let's learn how to use this command to undo commits. Instead of rewriting the history of our project like some other commands, Git Revert will create a new commit to undo the changes. The Git Revert command is used to undo commits in our repository. Later we may realize that some of these commits are unwanted and do not add any value to our project. When working with Git, we will make a lot of commits in our repository.
0 Comments
Leave a Reply. |