From the course: Git Essential Training
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Revert a commit
- [Instructor] In the previous video, we looked at how to view past versions of our project. Now, let's see how we can actually take back the changes in the previous version. Maybe we introduced a mistake or a bug that we need to undo. We can quickly fix that with git. First, let's check our commit history. I'll use git log --oneline. Now, let's say I want to undo the change where I renamed GitStatus.demo. To do this, I'll copy the commit ID and I'll use git revert and then copy and paste. When I press Enter, Git opens an editor message where I can modify the commit message for the fact that I have reverted. I like this message as it is, so when I close the editor, the commit is done. Now if I check my files on the left, I see that my file has been named back to gitStatusDemo.md. Now, it is important to note I am not actually rewriting history. That's generally considered bad practice because it can cause issues if others are working on the same code. Instead, what I have done is…
Contents
-
-
-
-
-
-
-
(Locked)
Git status2m 24s
-
(Locked)
Edit a file and view changes4m 14s
-
(Locked)
Delete files1m 35s
-
(Locked)
Rename files2m 18s
-
(Locked)
Working with folders3m 5s
-
(Locked)
Undo your changes2m 20s
-
(Locked)
View commit history4m 5s
-
(Locked)
Go back in Git history1m 52s
-
(Locked)
Revert a commit1m 55s
-
(Locked)
Make use of the GUI of Visual Studio Code2m 51s
-
(Locked)
Challenge: Make a change and revert51s
-
(Locked)
Solution: Make a change and revert2m 22s
-
(Locked)
-
-