Git Tutorial 5: Undoing/Reverting/Resetting code changes
Key Takeaways
Explains how to undo, revert, and reset code changes in Git
Full Transcript
hello and welcome to core basics coding tutorial and this tutorial we are going to see how to undo or reset or revert your code changes and get for this we are going to first clone our github repository in my previous tutorial I created this test repository I am just going to click here to copy the link and in git bash I will run git clone come on to clone the repository locally now I have this Secord directory and if you look at this directory I don't have any taste director here but once I clone it I will have it so now I got it ok now I'm going to open this test directory in 2py charm so I have opened it here already I have my Hungary code here you might be familiar with this code if you have watched my previous get tutorials all I'm going to do is make some changes and show you how you can undo those changes ok so the first item we are covering is undoing your uncommitted changes so let's say I change this code and add one new line alright so I am adding this new line I am running the program and then I realize that I am feeding too much junk to my kid you know I don't want my kid to look like this so I want to cut down on his Pisa intake so I will undo this one line alright for doing that I will go to my git bash first run git status come on I was not in this directory that's why I give me that error so I'm now in test directory running git status it is showing me I have changed hungry dot py file ok before this you see this useful tip it says you can then get check out - - filename to discard changes in your working directory so I'm just going to use this get check out - - file name is hungry dot py hit enter when I do that my Pisa change is gone all right now I can easily undo that change by removing that last line but when you are doing programming in real life you might have hundreds of lines of code changed for that you are not going to manually undo all of those lines right it's very cumbersome so that's why you you will use git checkout - - command ok now what if you have multiple files change so again you have let's say ah this file changed first of all and you have readme file change as well as the you added some garbage here and now when I do get status I will see two Faiza change one option is I do get checkout - - this file name first and then the second file name but there is a convenient option of using dot when you do dot it is going to undo all the files so when I do get status here you see both of these files are gone and when I open it here in my py charm code editor PISA is gone and that junk is gone alright so this was a quick demo on how to undo uncommitted changes but what if you have committed changes so let me first commit some changes all right so I have my PISA change I am going to commit that so always do get add to add your file to staging area then do git commit - M means message Fiza alright this commits my change how do you know it's committed you can always run git log and in the git log it is showing that this change is committed with this particular commit ID okay life is good so far I want to eat more junk food and I will say eat burger ok cool again go here and get ad now one thing you notice I always do get ad and then get do then do get commit right so there is one easy option called get commit - km now when i do - am the problem means is gonna probably add this one as well so ok i'm not going to do that so i will just do it ad hungry and then get - hamburger okay clear it and again check it log and now I have Pisa and burger both committed good all right now what I want to do is I want to undo this burger chain okay now I can't run git checkout - - because the change is already committed so for this you can use git revert come on okay now that command would need the commit ID so I am going to just copy it so double click here copy the commit ID and then run git reword that particular commit ID okay it's just showing the summary that you are rewarding that particular commit and you need to type column Q to close this UI and once you do that the change is committed so let me verify okay you see that Berger is gone okay and if you run git log here you will see there was a burger change and now there is a reward burger chain awesome so this looks good so far now one thing you might have noticed is when I did get reward it directly committed the change let's say I don't want to commit the change I want to run get reward and then I want to explicitly committed okay you can do that by using - and option so first let's look at log okay and now let's say I want to undo this work up this pizza chain okay so first you need to copy this okay and then do get every word - n so it's the same command that we ran previously but now we have - an option when you do this or a let me show here when you do this that change that P's aligned is gone all right but the change is not committed so if you do get status you will see now that file is modified it is uncommitted so now you need to explicitly commit it you can review your change and explicitly commit it and say we work visa so now when you do get log you will see the word Pisa here so the difference between supplying a - n option versus not supplying it is the - an option will not commit your changes versus if you don't supply anything it will just commit the changes okay okay now the third item we are covering today is git reset so I have all this git log history all right this shows the history in time of how my code evolved okay so in my code evolution let's say I want to go back to this status where I had Pisa and Burger both okay I realized that whatever changes I made after that they are not useful and I want to undo those changes okay so for doing that you can use git reset command so first let me copy which commit ID I want to go to so let's say I want to go to this status on Friday August 5 1954 so I will copy this and I will do get our reset - - hard let's commit ID and now I am when you say git log you'll notice all those river changes are gone and in your working directory you are back to eating peas and burger okay so git reset is actually quite powerful it takes you to any previous timestamp in your code history but at the same time it is destructive as well if you make a mistake then you will just lose all the changes so be very careful when you are using git reset command alright so that was all about undoing changes and gate thank you for watching
Original Description
In this tutorial, we will cover how to undo or revert a code change. Also I will show you how to reset your git branch to any previous commit id.
Here are the topics we will conver in this git tutorial,
1) Undo uncommited changes using,
git checkout --
2) Undo commited changes using,
git revert
3) Resetting changes using,
git reset
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Git Tutorial: https://www.youtube.com/watch?v=xAAmje1H9YM&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW
Next Video:
Git Tutorial 6: Branches (Create, Merge, Delete a branch): https://www.youtube.com/watch?v=sgzkY5vFKQQ&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW&index=6
Machine Learning Tutorial With Python: https://www.youtube.com/watch?v=gmvvaobm7eQ&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw
🌎 My Website For Video Courses: https://codebasics.io/
Need help building software or data analytics and AI solutions? My company https://www.atliq.com/ can help. Click on the Contact button on that website.
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from codebasics · codebasics · 47 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
▶
48
49
50
51
52
53
54
55
56
57
58
59
60
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
Related Reads
📰
📰
📰
📰
Scraping Indian government open data in 2026: what actually works
Dev.to · Manideep Chittineni
2026 Enterprise Data Recovery: What IT Teams Should Look For
Medium · AI
I Was Mad About the Jaylen Brown Trade. So I Simulated 10,000 Seasons to See If I Should Be.
Medium · Data Science
Mosaic Plots in Data Visualization: Turning Complex Relationships into Clear Business Insights
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI