Undo delete in GIT

守給你的承諾、 提交于 2019-11-28 04:37:46
manojlds

Do yourself a favour and do not do git checkout <hash> like the other answer suggests and go into more problems.

IF you have deleted file from your working directory and not committed the changes yet, do:

git checkout -f

CAUTION: commit uncommitted files before executing this command, otherwise you're going to lose them all

The deleted files should be back again.

If not and if you can find the commit that you want ( C, etc. - your question is not clear ) from git reflog, just do git reset --hard <hash from reflog> and you should be all set.

If I understood you correctly you rewrote commit C. So the original commit, let's call it C1 is not accessible from your commit graph, but it is still there (git keeps all commits for a while). Use git reflog to get the commit hash and git checkout <hash> or another appropriate command to get to the old state C1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!