无法恢复 Git 中的文件
可能的重复:
恢复 Git 存储库中已删除的文件
我有两个分支在我的 Git 中,master 和 newFeature。 在分支 newFeature 中,我首先在终端中物理删除了 fileA,然后在 Git 中通过
git rm fileA
随后运行,
git add .
git commit
现在,我再次需要 fileA。 我的想法是,只需切换到分支 master 即可将其恢复。 我显然错了,因为我找不到fileA。
如何使用 Git 取回 fileA?
Possible Duplicate:
Restore a deleted file in a Git repo
I have two branches in my Git, master and newFeature.
At the branch newFeature, I removed the fileA physically first in terminal and then in Git by
git rm fileA
Subsequently, I run
git add .
git commit
Right now, I need the fileA again.
I had the idea that I can get it back, by simply switching to the branch master.
I was apparently wrong, since I cannot find the fileA.
How can I get the fileA back with Git?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您需要找到
fileA
的最新版本。 您可以使用“git log -p”或“git Whatchanged”来检查它何时被删除,或者您可以使用“git ls-files revision> -- fileA”来检查文件是否被删除存在于给定提交中,其中“<修订>” 可以是master或newFeature^(newFeature^表示newFeature的父级)。然后你需要检查它,使用
或重定向“git show”输出
不要忘记将文件添加到git(如果需要)!
First, you need to find where you have last version of
fileA
. You can use "git log -p" or "git whatchanged" to check when it was deleted, or you can use "git ls-files <revision> -- fileA" to check if file is present in given commit, where '<revision>' can be master or newFeature^ (newFeature^ means parent of newFeature).Then you need to check it out, either using
or redirect "git show" output
Don't forget to add file to git (if needed)!
在删除 fileA 之前在提交处创建一个标记或分支,将其签出,将 fileA 复制到其他位置,然后再次签出
newFeature
分支。 其余的应该很简单。Create a tag or branch at the commit before you deleted fileA, check it out, copy fileA somewhere else, then checkout the
newFeature
branch again. The rest should be pretty simple.