In this article, we will learn about a very interesting git command called 'git restore'.
we will be discussing different use cases and real-life examples, and in the end, we will see one demo of 'git restore'.
Use cases of git restore :
1. git restore helps us unstage' or even discard 'uncommitted' local changes
2. It can be used to undo the effect of 'git add' and unstage the changes you have previously added in the staging area
3. It can also be used to discard local 'uncommitted' changes in your project, restoring the last committed state.
Real-Life Example :
Let's say your technical club organizes one hackathon, and today is the award ceremony for it. The announcers are just announcing the winners.
So, the announcer, by mistake, calls "Team 30" the winners, and he calls that team on the stage.
But the real winners were "Team 13" so the next task of the announcer would be to apologize to the team which was on stage and unstaged them(Team 30)
The next task here would be to call the correct winners on stage, so the announcer now announces the correct winners (Team 13) and calls all of them on stage, and then all the winners are awarded trophies.
So, this was one example by which you can relate and understand the use of the 'git restore' command.
Let's say there is one file and you make some changes to it, and then you add those changes to the staging area with the help of 'git add' but later you realize that you have added the wrong files on the staging area so, in this case, you can always unstaged the wrong changes you have done and then stage the changes that you want to do.
Example
1. Let's start with an empty HTML file.
2. Let's make some changes to this file and then check the status
3. Let's add this file to the staging area and again check the status of the file
4. Let's unstage this file using git restore
git restore --staged [file_name]
5. Let's check the status again
6. Let's discard the uncommitted change
git restore [file_name]
7. If we see the file now then it will be at its initial stage
8. Finally, let's do some necessary changes and add this file to the staging area and then commit them.
So, this was the practical example of git restore, I hope you have understood the concept of 'git restore'.
YouTube Video Link : https://youtu.be/Nn-Qh-y7wj4
Connect with me : https://linktr.ee/Devgrammer
I will be publishing this article on GeeksforGeeks as well. Check my profile https://auth.geeksforgeeks.org/user/sanketsjagdale999