Free cookie consent management tool by TermsFeed Generator how to use git restore and completely ignore the changes: 3 scenarios (video) | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
how to use git restore and completely ignore the changes: 3 scenarios (video)

how to use git restore and completely ignore the changes: 3 scenarios (video)

Last Updated on Nov 27, 2022

https://youtu.be/gv6qSY0Hv1s

 

Transcription

Hello

This is amir

Today we are going to talk about ways to ignore the edits we made in a git project and restore the changes by git restore

So let’s get started

Types of changes

There are 2 main types of edits we make in a project

  1. The first one is creating a file
  2. And the second one is updating or deleting a file

Untracked (remove)

In the first scenario that we have created a file, the file is going to be shown as untracked.

Here I create a file named 1.txt and as you can see it’s untracked.

If you want to ignore it, you don’t need to do anything inside git you can simply delete the file

And when you run

git status

it doesn’t show that file

great

Changed (git restore)

Now let’s talk about the second scenario when you changed a file

Here I’m creating a file named 1.txt again

Let me add and commit the changes.

git add .

and then

git commit -m "changes added"

Now let’s change it and write hello world

Ok great

Now if we run

git status

It it show as changed

If you want to ignore this changes

Then as it’s written here

Just run the command

Git restore file-name

and then the name of the file which in this case is 1.txt

Git restore 1.txt

Staged (unstage)

Now you might ask what if I have already added the file but haven’t committed yet

Then for both of the scenarios, whether you’ve created a file or updated or deleted a file, it’s going to be listed as staged

So in this case you have to unstage it first.

And to do that You should run the command

Git restore --staged file-name

and then the file name

When you unstage it Then it shows the file like before as changed or added

Practice

Let’s practice together

Question

Here I initialize a git project I create a file named a.txt and commit the changes

Now I add a new file called b.txt

I also write “my name is amir” in a.txt

And I add them all but I haven’t committed yet.

Now I have changed my mind and I want to ignore all the changes and go back to before when there was only one file called a.txt and there was nothing written in it.

How can I do it?

Pause the video

Try to do it

Write your answer in the comment and then play the video to see the answer

Answer

Now let’s see the answer

As you can see all the files are in the staged area so I should unstage them first by running the command

Git restore --stage .

Then for a.txt that is shown as changed

I should restore it by running the command

git restore a.txt

And for b.txt that is shown as untracked I can simply remove it

Was your answer correct? Write in the comments

Key Takeaways

Just a quick recap:

  • We talked about ignoring the changes in a git project
  • If we created a file we simply remove it
  • If we changed or deleted a file we can restore it
  • And if it’s shown as stages we should first unstage it and then ignore it

Final Words

And finally

if you liked what you learned please like and subscribe

That would be a great motivation to do more videos

If you have any suggestions or questions please leave a comment below and I try to answer them as soon as possible

That’s it

Have a wonderful day.

You can watch the original video on youtube.

Category: programming

Tags: #git

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

Top 5 websites to learn PHP for FREE
Dec 22, 2022 programming

Top 5 websites to learn PHP for FREE

Do you want to learn PHP but you don’t want to spend hundreds of dollars? You are not alone. There are many websites that help people like you and me to start our journey. ...

9 Min Read Read More
PHP class
Mar 22, 2023 programming

PHP class

Today we are going to talk about classes in PHP. This is an introduction to a series of posts that would cover the topic of object oriented programming in PHP. class is the first one. ...

8 Min Read Read More
PHP Array Sort
Feb 14, 2023 programming

PHP Array Sort

Today we are going to talk about sorting arrays in PHP. we will take a look at some of the most useful and common array sort functions in PHP and compare their functionality. ...

7 Min Read Read More
PHP Sanitize Data
Feb 15, 2023 programming

PHP Sanitize Data

Today we are going to talk about sanitizing data in PHP. Sanitizing data is a very important step, especially when you are dealing with user data. ...

7 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...