简体   繁体   English

错误地在Git中删除了目录

[英]deleted directory in Git by mistake

By mistake I have deleted a directory in my git repo, and commited it. 我错误地删除了我的git仓库中的目录,并提交了它。

I have done 我已经做好了

git checkout LONG_SHA_ID

where LONG_SHA_ID is the ID of the previous commit, and I have got the directory back, but also I have got back the previous versions of some files that I have fixed in the latest commit. 其中LONG_SHA_ID是前一次提交的ID,我已经恢复了目录,但是我还找回了我在最新提交中修复过的某些文件的先前版本。

How can I get back the deleted directory, with the latest version of the other files? 如何使用最新版本的其他文件取回已删除的目录?

做这个:

git checkout LONG_SHA_ID -- /path/of/directory/you/deleted

Checkout the branch with the fixed files, and do git reset --mixed HEAD^ . 用固定文件签出分支,并执行git reset --mixed HEAD^ This will undo the commit so you can try again without deleting the folder. 这将撤消提交,以便您可以再次尝试而不删除该文件夹。

Just revert back the last commit by 只需恢复最后一次提交

git revert HEAD

That will back out the most recent commit. 这将取消最近的提交。 Then just push it up. 然后把它推上去。 You can replace HEAD with the revision you want out. 您可以将HEAD替换为您想要的修订版。

For more details about undo a git commit, look on here 有关撤消git commit的更多详细信息,请查看此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM