[英]recovering deleted files git after revert
I have a new repository.我有一个新的存储库。 I added some files (a,b,c) via
我添加了一些文件(a,b,c)通过
git add .
git commit -m "x"
I realized file c was unnecessary so I looked for the last commit via我意识到文件 c 是不必要的,所以我通过以下方式查找了最后一次提交
git log
with the commit id at hand I did手头的提交 id 我做了
git revert commit-id
it started deleting all files removing file abc它开始删除所有文件,删除文件 abc
How can I restore them?我怎样才能恢复它们? I looked at the log and only the original commit x is in there.
我查看了日志,只有原始提交 x 在那里。
I tried我试过
git checkout HEAD^^ -- .
as per How do I "un-revert" a reverted Git commit?根据如何“取消还原”已还原的 Git 提交?
but I get "Invalid reference HEAD^^"但我得到“无效的参考 HEAD^^”
any ideas?有任何想法吗?
Have you tried你有没有尝试过
// It will reset your commit back to previous if its 2 commits back then use head~2 etc.
git reset head~1
git reflog
(this is essentially a log of all of the recent HEADs of your branch - very useful for scenarios like this).git reflog
获取您在其中添加文件的初始提交的提交哈希(这本质上是您分支的所有最近 HEAD 的日志 - 对于此类场景非常有用)。git reset --hard <commit-id>
replacing the hash with the hash of the initial commit where you added the files.git reset --hard <commit-id>
将哈希替换为您添加文件的初始提交的哈希。 If you want to temporarily go back to this commit then do a git checkout <commit-id>
.git checkout <commit-id>
。 Further reading on git reflog
: http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html进一步阅读
git reflog
: http : //gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.