Source From Here
Question
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 version. I have done a git log along with a git diff to find the revision I need, but just have no idea how to get the file back to its former state in the past.
How-To
Assuming the hash of the commit you want is c5f567:
The git checkout main page gives more information. If you want to revert changes made to the files in commit c5f567 and subsequent commits, you have to pass the commit just before it. You can use refer to that commit as c5f567~1. As a side note, I've always been uncomfortable with this command because it's used for both ordinary things (changing between branches) and unusual destructive things (discarding changes in the working directory).
Below is a demonstration on above description:
Question
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 version. I have done a git log along with a git diff to find the revision I need, but just have no idea how to get the file back to its former state in the past.
How-To
Assuming the hash of the commit you want is c5f567:
The git checkout main page gives more information. If you want to revert changes made to the files in commit c5f567 and subsequent commits, you have to pass the commit just before it. You can use refer to that commit as c5f567~1. As a side note, I've always been uncomfortable with this command because it's used for both ordinary things (changing between branches) and unusual destructive things (discarding changes in the working directory).
Below is a demonstration on above description:
沒有留言:
張貼留言