恢复到 git 修订版的先前版本并推送它以使其成为新的头部?

Reverting to previous version of git revision and push it to make it the new head?

我需要在大约 3 次推送前制作最新版本的 git,我不确定如何使用 TortoiseGit 来完成。

我已经尝试将每次提交的更改还原到我想要的那个,但这导致了很多意外的问题,包括损坏和文件冲突。

我觉得应该有一个简单的方法来简单地说 'make revision xyz the latest and push that up'。

  1. 找到您认为是正确修订的提交。假设它是 abc123.
  2. 对于您已推送和更新的远程存储库中的分支,运行 git push origin -f abc123:<branch_namr>。它用 abc123 覆盖分支作为其新的头提交。以防万一你可能会后悔,你可以从当前头git branch foo创建一个备份分支。而如果你想撤消强制推送,你可以运行git push origin -f foo:<branch_name>。如果没有备份,可以通过git reflog.
  3. 找到之前的头像
  4. 对于您当地的分支机构,运行 git checkout <branch_name>;git reset abc123 --hard

这个this wiki for instance:

  • Use the TortoiseGit command: Git Show Log
  • Select the commit point before our problem started.
  • Use the TortoiseGit command: Reset "BRANCH" to this...
    • Where BRANCH represents the name of the branch being used.
  • Use the Hard option
    • This will remove all the commit points above this point in Git AND
    • The working files will be reset back to the condition at that point of the project.

然后,仍然使用 TortoiseGit,push with the force option activated