![]() If you use the Git tool known as GitKraken, you need to right-click on a commit from the central graph and choose revert commit from the context menu. We enter the following Git revert /c/revert example/Īnd presto! The charlie.html is gone, as another directory listing will /c/revert example/Īlpha.html beta.html delta.html edison.html That’s the third commit, with the ID of 4945db2. So, we decide that the charlie.html file needs to go. & git commit -m "5th git commit: 5 files"Īfter the initial command batch, we can do a directory listing and see five files residing in the current /c/revert example/Īlpha.html beta.html charlie.html delta.html edison.htmlĪnd the git reflog command reveals the history of the current /c/revert example/ & git commit -m "4th git commit: 4 files" & git commit -m "3rd git commit: 3 files" & git commit -m "2nd git commit: 2 files" Whenever we create a new file, we add it to our Git index and create a new commit that contains a meaningful /c/revert example/ Now, we add five files to the repository (or “repo”). Initialized empty Git repo in C:/git revert example We begin by creating a clean repository with the git init /c/revert example/ Here’s an example of how to revert Git commit using syntax resources from TechTarget. Since Git reset and Git revert have a shared affinity, we will explain a little more about Git reset at the end of this article. This process is time-consuming and inelegant. The programmer must remove every commit that occurred after the offending commit, remove the target commit, and put all subsequent commits back in place. So, whereas a Git revert can target one old commit, a Git reset is more involved. First, Git revert can focus on one particular commit at a chosen point in history, while Git reset only works backward from the user's current commit. There are two notable differences between Git revert and Git reset. Unlike other "undo" commands like Git checkout and Git reset, which move the branch and HEAD ref pointers to a specific commit, Git revert inverses the changes in a particular commit, creating a new "revert commit." Then, it updates the ref pointers to point at this new revert commit and makes it the branch tip.īear in mind, Git revert doesn’t undo a commit in a project history it reverses the changes done in the offending commit and appends a new commit with the opposite effect. Rather than going in manually, fixing the bug, and committing a new snapshot, Git revert will automatically do all the work for you. The ability to Git revert a previous commit comes in handy when you’re tracking down a bug and discover that it was introduced via a single commit. This process stops Git from losing history, which is vital for the revision history’s integrity and promoting smooth, reliable collaboration. Rather than removing the commit in question from the project history, the Git revert figures out how to invert (or reverse) the changes created by the commit, then appends a new commit containing the new inversed content. 'git revert 31416p54' How Does Git Revert Work? Here’s what the syntax would look like if you wanted to revert a Git commit called 31416p54: The Git revert command syntax is straightforward.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |