如何撤消还原操作以返回到git中以前的提交

2024-04-29 09:03:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我运行了revert命令来撤消以前的提交,但后来意识到我犯了一个错误

如何撤消还原操作并恢复到以前提交的状态

例如:

(1)在我的项目中,我有两个文件A和B,然后我提交了更改并将更改推送到GitHub

(2)我添加了文件C并提交了更改,但没有将更改推送到Github

(3)我运行了恢复,从我的项目中删除了文件C,但这是一个错误

我如何撤销我的上一次恢复操作以恢复文件C,该文件已提交,然后在本地回购中恢复,但从未推送到Github


Tags: 文件项目命令github状态错误意识revert
2条回答

“git reflog”列出最后几个标题。 选择所需更改的提交id。 git重置为该提交id

Dangit, I did something terribly wrong, please tell me git has a magic time machine!?!

git reflog
# you will see a list of every thing you've
# done in git, across all branches!
# each one has an index HEAD@{index}
# find the one before you broke everything git reset HEAD@{index}
# magic time machine

You can use this to get back stuff you accidentally deleted, or just to remove some stuff you tried that broke the repo, or to recover after a bad merge, or just to go back to a time when things actually worked. I use reflog A LOT. Mega hat tip to the many many many many many people who suggested adding it!

资料来源:https://dangitgit.com/en#magic-time-machine

相关问题 更多 >