User Tools

Site Tools


git:git-reset-file-to-previous-commit

Back to git main page

Suppose we will revert the content of file1.txt to his version in a previous commit.

First we search for all the commits where file1.txt has been modified (or created).

git log --oneline file1.txt

Then will return something like that, with the commit hash codes in the first column :

4edb624 (HEAD -> master, origin/master, origin/HEAD) more updates
431261f add some new stuff
2ae05f4 update some files
71aa3c6 initial commit

Here we choose for example that commit “update some files” with hash code 2ae05f4 has the correct version of file1.txt and we revert the content of file1.txt with :

git checkout 2ae05f4 -- file1.txt
git/git-reset-file-to-previous-commit.txt · Last modified: 2023/03/31 12:17 by 127.0.0.1