简体   繁体   English

将 GitHub PR 恢复为特定提交

[英]Revert a GitHub PR to a particular commit

I've created a new GitHub PR for branch new-feature , it has 10 commits.我为分支new-feature创建了一个新的 GitHub PR,它有 10 个提交。

I want to revert it to be at the 5th commit.我想将其还原为第 5 次提交。

What is the proper workflow?什么是正确的工作流程?

Notes:笔记:

If I'm on new-feature and use git reset --hard <sha-of-my-5th-commit> , this will just move my local state back.如果我使用new-feature并使用git reset --hard <sha-of-my-5th-commit> ,这只会将我的本地状态移回。 I'm not sure how to affect github's history with this我不确定如何用这个影响 github 的历史

Please be careful with hard resets and push force.请小心硬重置和推动力。 You should back up stuff before resetting.你应该在重置之前备份东西。 But,但,

After git reset --hard <sha-of-my-5th-commit> you can rungit reset --hard <sha-of-my-5th-commit>之后你可以运行

git push -f

to overwrite the remote branch.覆盖远程分支。

If you want to actually record the history after a reset with a differentiating commit or if force push is disabled, use the following commands:如果你想在有区别的提交重置后实际记录历史记录,或者如果强制推送被禁用,请使用以下命令:

After git reset --hard <sha-of-my-5th-commit> :git reset --hard <sha-of-my-5th-commit>之后:

  git reset --soft FETCH_HEAD
  git commit -m "describe the changes you reset"
  git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM