[英]Recovering ignored files deleted by Git when checking out prior commits
Did a commit, then pushed to the repository. 进行提交,然后推送到存储库。 Have a couple of files that git ignores, but that is okay, I have a local copy, right? 有几个git忽略的文件,但是没关系,我有本地副本,对吗? Learned how I could check out past versions. 了解了如何查看过去的版本。 Great! 大! Loved it! 爱它! Then tried to go back, but my ignored versions are gone! 然后尝试回去,但是我忽略的版本不见了! I don't show it below, but believe me they are gone. 我没有在下面显示,但请相信我,他们已经消失了。 How do I recover them? 如何恢复它们? If not possible, what should I read to prevent this from ever happening again? 如果不可能,我应该读些什么以防止这种情况再次发生?
1014 git status
1015 git checkout 084322b33
...
1040 git checkout 32484241e
1043 git status
1044 git reset --hard origin/master
1045 git fetch origin
1042 git reset --hard origin/master
1047 git pull origin master
1048 git status
As mentioned that you checked out a commit and then you saw that the files that were ignored were gone now... 如前所述,您签出了提交,然后您发现被忽略的文件现在消失了...
This happened NOT because of git but because of someone deleting it manually . 发生这种情况不是因为git,而是因为有人手动删除了它。
Reason 原因
This is because the files were untracked and hence git was not bothered about them and hence could not be the one who deleted it. 这是因为文件没有被跟踪,因此git不用理会它们,因此不能成为删除该文件的人。
Avoidance 回避
Access control can be one way. 访问控制可以是一种方式。 Make sure the right user has the right permissions for the file/directory. 确保正确的用户对文件/目录具有正确的权限。
Create a backup if you need . 如果需要,请创建备份。
Just be careful 小心一点
Or Since git 1.7.7 you can save the untracked files in stash by using 或从git 1.7.7开始,您可以使用以下方式将未跟踪的文件保存在存储中:
git stash -u
And read this article this article before you use this command. 并在使用此命令之前阅读本文和本文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.