Git 返回到特定的提交

  • 本文关键字:提交 返回 Git git
  • 更新时间 :
  • 英文 :


我现在正在执行这个:

git reset --hard shaCommit .

我会将我的代码收回到特定的先前提交,但是,我该如何推送它?假设我最后的 4 次提交是垃圾,我想回到特定的提交,但是当我尝试推送时出现此错误:

$ git push
To ssh://git@uk-gitlab.almuk.corp/warlocks/capexbaar-web.git
 ! [rejected]        development -> development (non-fast-forward)
error: failed to push some refs to 'ssh://git@uk-gitlab.almuk.corp/warlocks/capexbaar-web.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

建议您在此处查看此答案 类似问题

引用原始接受的解决方案

只需做:

git push origin <your_branch_name> --force

或者,如果您有特定的存储库:

git push https://git.... --force
您必须

使用命令强制推送 git push -f .

如果在强制推送之前拉取更改,它将下载所有更改并执行合并提交。

如果您与存储库中的其他人一起工作,并且已经推送了要删除的提交,通常最好不要修改历史记录,这样您就不会搞砸其他人正在做的事情。

为此,您可以推送新的提交以将更改还原到该状态,而不仅仅是删除旧提交:

git checkout shaCommit -- .
git commit -a

有关更多详细信息,请参阅还原多个 git 提交

最新更新