可以使用“git rm -r -f<目录>”吗?命令被恢复?目录>
我正在设置我的第一个 git 存储库,并执行了以下操作,
git init
然后是一些 git-config 内容来设置远程服务器。然后我做了
git add directory
git status
哎呀,我添加了一些我不想要的文件。好的,所以我应该 git rm 从提交列表中删除该目录并重新开始
git rm directory
此时我应该正确阅读控制台消息和文档......但没有。于是我就跑了
git rm directory -r -f
嗯?我的目录去哪儿了?啊,好吧,git 已经删除了它,所以它“不存在”了。所以让我们尝试一下,
git status
git reset --hard
在没有成功、一些错误消息和一堆网络搜索之后,我意识到我的失礼。我应该使用
git rm -r --cached directory
它将其从提交列表中删除,但不从我的文件系统中删除。哎呀。幸运的是没有造成严重损失。
似乎应该有一种方法可以从中恢复,但我的大多数搜索最终都指向“--cached”选项......而且现在有点晚了。没有提交,所以我不能只恢复/拉取文件(只有本地副本)。
是否可以找回这些文件?
I was setting up my first git repository and did the following,
git init
follow by some git-config stuff to setup the remote server. I then did
git add directory
git status
Whoops, I added some files which I did not want. Okay, so I should git rm to remove the directory from the commit list and start again
git rm directory
At this point I should have read the console message and documentation properly....but didn't. So I ran
git rm directory -r -f
Huh? Where did my directory go? Ah, okay, git has removed it so it is "not there" any more. So lets try,
git status
git reset --hard
After no success, some error messages and a bunch of web searches, I realised my faux pas. I should have used
git rm -r --cached directory
which would have removed it from the commit list, but not from my file system. Whoops. Fortunately nothing serious lost.
It seems like there should be a way to recover from this, but most of my searches end up pointing to the "--cached" option...and it is a bit late for that. There are no commits, so I can't just revert/pull the files (there was only a local copy).
Is it possible to get those files back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
并且
答案是否。
没有提交,因此您没有使用源代码控制。
这些文件从未进入对象数据库。一般来说,你永远无法在 git 中取回未提交的内容。您通常可以取回之前提交的内容。
经验法则:经常提交
编辑
另请参阅
and
The answer is no.
There are no commits, hence you are not using source control.
The files never entered the object database. In general, you can never get uncomitted stuff back in git. You can most often get previously committed stuff back.
Rule of thumb: commit often
Edit
See also
我犯了完全相同的错误,但尽管之前将文件添加到 git 索引,但我无法使用“git fsck --lost-found”恢复它们。幸运的是,我记得 IDE 中的“本地历史记录”跟踪选项,因此使用它,毫无问题地恢复了除库二进制文件之外的所有代码:)
I did exactly the same mistake, but in spite of adding files to the git index earlier, I couldn't recover them using 'git fsck --lost-found'. Luckily, I remembered the 'Local history' tracking option in my IDE so using it, without no problem I recovered all the code except of library binaries :)