撤消在git中删除的文件? [英] Undo deleted files in git?

查看:81
本文介绍了撤消在git中删除的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想把我的网站推到一个git仓库,所以我使用了git add命令。然后,在我进行提交之前,我意识到我已经从根文件夹中添加了所有内容,而不仅仅是我想要的目录。由于我不想这样做,我使用git rm -chached命令来删除所有内容,认为我只是在改变推送给git的东西。我也用git clean。



现在,我意识到这些命令实际上删除了我网站上的文件!我做了什么?如果有人能帮我把事情弄回原处,我会非常感激。
-JB

解决方案

您可以这样做

  git reset --hard HEAD ^ 

版本历史记录,有效地撤销上次提交,包括所有删除操作。



如果您已经推送了更改,您可以改为

  git revert HEAD 

创建一个新的提交恢复删除提交,然后推送它。



这个答案假定您确实提交了更改,并且这是您所做的最后一次提交。如果你没有做出改变,威利的答案会更好。


Newbie needs some help undoing a mess!

I was tring to push my site to a git repository, so I used the git add command. Then, before I did the commit, I realized I had added everything from my root folder instead of just the directory I wanted. Since I didn't want to do that commit, I used the git rm --chached command to remove everything, thinking I was only changing what would be pushed to git. I also used git clean.

Now, I realize those commands actually deleted the files on my site! What have I done? If anyone can help me put things back in place, I would really appreciate it. -JB

解决方案

You can do

git reset --hard HEAD^

To move one step back in the version history, effectively undoing the last commit including all deletes.

If you have already pushed your changes you can instead do

git revert HEAD

To create a new commit reverting the delete commit, and then push that.

This answer assumes that you did commit the changes, and that was the last commit you did. If you didn't commit the changes, Willy's answer is better.

这篇关于撤消在git中删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆