Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Revert a single file to its last commit [duplicate]

Tags:

git

I want to revert a file to its state on its last commit.

I have modified, added and committed other files. But there is that one file that I didn't stage.

I want to revert it's state (only the state of that file) to the last commit that that file was committed.

In other words, I just want to ignore the last changes made to that file and restore it to the last point it participated in a commit.

like image 234
vinicius de novaes Avatar asked Jun 12 '26 00:06

vinicius de novaes


1 Answers

You can use:

    git checkout <file-with-path>

Or

    git restore <file-with-path>

Git checkout would work if you had already committed the file. If the file was already staged you could add --staged flag to git restore to restore it as well.

https://git-scm.com/docs/git-restore

like image 113
glco Avatar answered Jun 15 '26 12:06

glco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!