一些脚本错误地从我用GIT跟踪的目录中删除了一些文件。我还没有提交这些更改。当我运行git status时,我看到几乎所有的100+文件都被删除了,并且显示为Changes not staged for commit,所以我甚至还没有运行git add。
什么是最好的方法来恢复所有这些文件,并回到我所在的地方。注意:我没有对此存储库进行任何其他更改。我通过运行git status看到的所有更改都是错误删除的文件。
发布于 2016-08-12 23:37:51
在这种情况下,“我没有对这个repo.进行任何其他更改。通过运行git status我看到的所有更改都是错误删除的文件。”
git reset --hard发布于 2016-08-13 03:16:59
有两件事,如果您想要删除本地未提交的文件更改,那么只需运行
git checkout . # Do to show you need to be in the project main directory otherwise command may fail
# Also you can mention the individual all file but then would be hectic in this case但是,如果您已经在本地提交了一些文件,并且希望也恢复它们,那么可以多次运行此命令,直到使用git log看不到本地提交日志为止
git reset --hard HEAD^ # this will reset the git commit 1 step back然后更新本地存储库
git pull origin <branch_name>发布于 2016-08-13 03:22:15
如果进行了其他更改,所以您不想删除,但所有要取消删除的文件都在同一目录中,您可以签出目录:reset --hard:
git checkout HEAD /path/to/fileshttps://stackoverflow.com/questions/38921512
复制相似问题