
To revert the last commit in a remote repository, you have to follow all the steps to revert the last commit in your local repository. New commit generated after using git revert Reverting the Last Commit in Remote The default message will start with the text “Revert” followed by the commit message of the commit being reverted. Git will also prompt you to add a commit message.

Once you use the revert command, your terminal should display the following message:

Use the current commit id or the HEAD keyword if you want to revert the last commit changes. In my case, the current commit id is 98cfeb4.ģ. The first commit id logged in the terminal is the current commit where you are now. Terminal result from using git log –oneline command git log -onelineįor instance, this is the list of previous commits I have in my current project. Otherwise, it will display other information such as the author and date of each commit, which is not needed to revert the last commit. I recommend using the -oneline flag to get the information of previous commits in one line. To do so, we will use the log command to display the list of previous commits we have made. Now, we need to get the id of the current commit. You will know there are no changes in your current branch if your terminal does not display the following message:Ģ. Let’s make sure we don’t have any changes in the current branch by using the status command.git revert HEAD Reverting the Last Commit Locally

Hence, if the current commit is C, then HEAD will pull the commit id of C. The keyword HEAD is another way to say the current commit. git revert CĪnother option is to use the keyword HEAD instead of the commit id. In case we want to revert the changes made from B to C, what we need to do is to use commit C to revert to the state of B. Let’s use the previous diagram as a repository example where we have git commits of A, B, and C, and C is the current commit. Using the revert command in Git is as simple as providing the commit identifier.
