DEV Community

AquaCat
AquaCat

Posted on

【Github】How to restore the status of the file in your working directory

You are coding and you hit the command "git add ." and "commit -m XXX (comment) ." Then, you noticed some files that you believe that you have not changed on the ""modified files" list. Do not panic.

1.Hit "git reset --soft HEAD^" to cancel the commit.
2.Hit "git restore --staged " to unstage the file.
3.Hit "git diff -- " to check what has been changed in these files are really changed.
4.If you think that those changes would not be a problem, hit "git checkout " to restore the status of the file (restore the status before the commit was executed.)
This is like a "transaction." If you hit "git checkout ," those changes that were added to the file will not be
restored ,ever again. Make sure there would be no problem after you execute "git checkout."

Top comments (0)