Learn Version Control with Git
)}

git revert

The git revert command is a helpful command to non-destructively reverse changes in your repository history.

git revert will try to reverse the changes and create a new commit with the reverted changes.

let's add some text to our file:

echo "This is a useless feature" >> project-1.txt

let's stage and commit this new modification:

git add .
git commit -m "added a useless feature"

let's view our history:

git log

We realize that this feature is useless, and would like to get rid of it, let's revert it,

git revert --no-commit e13a0f47f6ff45394780601ef346ede765468b17
git commit -m "reverted useless feature"

the third parameter is the SHA of the commit you would like to reverse, the SHA for added a useless feature is e13a0f47f6ff45394780601ef346ede765468b17, in my case, yours will be different. This is followed by a message describing the revert.

--no-commit allows us to revert the change without committing. Without it, you will be redirected to a vim editor to create your commit. We will be creating our commit in the next line using git commit.

Good Job. We successfully reverted our changes from the latest commit.

Feedback Summary
5.0
3 students
5

100%
4

0%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.