【发布时间】:2021-04-11 09:51:54
【问题描述】:
我有三个提交,我尝试恢复到第一个提交。在这样做时,Git 删除了两个文件,我不知道为什么它们在我尝试恢复的第一次提交中。如果 Git 删除的两个文件在原始提交中,为什么要删除它们?
这是我使用的代码:
git revert <commit id>
这是错误信息:
Removing style.css
CONFLICT (modify/delete): pages/services.html deleted in (empty tree) and modified in HEAD. Version HEAD of pages/services.html left in tree.
Removing index.html
error: could not revert 9b23173... inital commit
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
【问题讨论】:
-
git revert恢复提交,而不是提交。我假设您打算恢复其他提交。另见stackoverflow.com/a/4114122 -
git revert用于恢复提交本身,而不是“恢复到提交”。你正在寻找git reset --hard之类的。 -
好吧,但是我想重置到旧的提交,同时保留历史以防万一我想再次返回,我是否仍然使用 reset --hard?
-
您可以还原一系列提交。例如,您可以执行
git revert HEAD HEAD~1来恢复当前提交和前一个提交。您还可以使用提交范围等。 -
那么您应该使用
git checkout在提交时查看存储库状态,同时保留您的历史记录(分支所在的位置等)
标签: git git-commit git-revert