How to restore a whole directory from history of git repository?
I would like to restore a whole directory (recursively) from the history of my git repository.
There is only 1 branch (master).
I know the commit where errors were included.
Can I use the sha1 hash of the parent commit to restore the state of the directory as it was before the errors were included?
I thought about something like this:
git checkout 348ce0aa02d3738e55ac9085080028b548e3d8d3 path/to/the/folder/
but it did not work.
尝试在修订和路径之间添加' - ':
git checkout 348ce0aa02d3738e55ac9085080028b548e3d8d3 -- path/to/the/folder/
There are two easy ways to do this:
If the commit that included the errors only included the errors, use git revert
to invert the effects of it.
If not, the easy path is this:
git checkout 348…
cp -a path/to/the/folder ../tmp-restore-folder
git checkout HEAD # or whatever
rm -rf path/to/the/folder
mv ../tmp-restore-folder path/to/the/folder
git add path/to/the/folder
git commit -m "revert …"
If you simply do git checkout <SHA-ID>
then it will temporarily move you to that sha-commit.
Each commit object holds the entire structure of the disk at that time, so if you have files there and need to copy them out, you can do so. Warning though, you will not be in any branch, so you'll have to move back to master before copying the file into your working tree and commit it.
链接地址: http://www.djcxy.com/p/18948.html