Reverting A Commit
What Is A Revert?
When you tell Git toreverta specific commit, Git takes the changes that were made in commit and does the exact opposite of them. Let's break that down a bit. If a character is added in commit A, if Git_reverts_commit A, then Git will make a new commit where that character is deleted. It also works the other way where if a character/line is removed, then reverting that commit will_add_that content back!
We ended the previous lesson with a merge conflict and resolved that conflict by setting the heading toAdventurous Quest
. Let's say that there's a commit in your repository that changes the heading now toQuests & Crusades
.
Thegit revert
Command
Now that I've made a commit with some changes, I can revert it with thegit revert
command
$ git revert <SHA-of-commit-to-revert>
Since the SHA of the most-recent commit isdb7e87a
, to revert it: I'll just rungit revert db7e87a
(this will pop open my code editor to edit/accept the provided commit message)
I'll get the following output:
Did you see how the output of thegit revert
command tells us what it reverted? It uses the commit message of the commit that I told it to revert. Something that's also important is that it createsa new commit.
Revert Recap
To recap, thegit revert
command is used to reverse a previously made commit:
$ git revert <SHA-of-commit-to-revert>
This command:
- will undo the changes that were made by the provided commit
- creates a new commit to record the change
Further Research
- git-revert from Git Docs
- git revert Atlassian tutorial