I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous versio
For me none of the reply seemed really clear and therefore I would like to add mine which seems super easy.
I have a commit abc1
and after it I have done several (or one modification) to a file file.txt
.
Now say that I messed up something in the file file.txt
and I want to go back to a previous commit abc1
.
1.git checkout file.txt
: this will remove local changes, if you don't need them
2.git checkout abc1 file.txt
: this will bring your file to your wanted version
3.git commit -m "Restored file.txt to version abc1"
: this will commit your reversion.
git push
: this will push everything on the remote repository Between the step 2 and 3 of course you can do git status
to understand what is going on. Usually you should see the file.txt
already added and that is why there is no need of a git add
.