Undo a previous commit
Create a negative of a past commit with the revert
command
Committed some changes and wish you hadn’t? No worries, you can undo a previous commit with the revert
command. This will prepare a commit that is the negative of the commit you want to undo.
Go to your repo history
Open the workspace of the repo where your changes are. Make sure that you have no pending changes. On the left-hand side, click on the “History” tab.
Select commit to revert
Click on the menu icon next to the commit you want to revert, and select “Undo this commit”. In the modal window, click “Undo changes”. It’s possible you’ll have to resolve a merge conflict, see below.
Admire your work
You’ll see new changes in your workspace that undo the changes for your commit.
In this example, this is the commit I chose to undo:
And this is the resulting change in my workspace:
Resolve a merge conflict?
If you try to revert a commit that affects a file that was also affected by a later commit, it will result in a merge conflict. You’ll have to resolve the conflict before you can commit the changes.
Earlier, I reverted a file that was edited. Now, instead, I’ll try to revert an earlier commit - the one where the file was created.
This will result in a merge conflict, which you’ll have to resolve before you can commit the changes.