【问题标题】:How to undo several Git commands? [duplicate]如何撤消多个 Git 命令? [复制]
【发布时间】:2016-03-19 18:00:52
【问题描述】:

有机会撤消以下任何行:

git rm cvs
git rm cvs -r
git reset HEAD --.
git reset --hard HEAD
git reset --hard
git clean -df
git status
git rm --cached .
git rm --cached
git rm --cached -r
git rm --cached -r --ignore-unmatch
git rm --cached -r --ignore-unmatch .

【问题讨论】:

  • 您是否尝试撤消最新的特定提交?
  • 我认为 git clean -df 删除了一些重要文件。我不确定。
  • git clean 将删除 未 存储在 git 中的文件,因此除非您有备份,否则请放手,因为它们已经消失了,伙计。如果您删除了实际存储在 git 存储库中的文件,则通常可以从较早的提交中检索它们。
  • 您需要的所有信息都在这里:stackoverflow.com/questions/34519665/… 阅读 reflog 并使用它恢复到您想要的时间点。

标签: git undo rm


【解决方案1】:

要从最后一次已知的良好提交撤消特定提交,首先查看git log,您应该会在 shell 中看到:

commit: your40characterSHA1codehere # copy this into the clipboard
Author: your name here with email address
date: date-here

Commit message here

您应该复制commit sha1 代码,然后执行git reset --hard your40characterSHA1codehere 和git push origin master --force 强制推送您工作的主分支或其他分支。希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 1970-01-01
    • 2018-05-30
    • 2016-10-03
    • 1970-01-01
    • 2017-04-23
    • 2017-05-27
    • 2019-03-18
    • 1970-01-01
    相关资源
    最近更新 更多