简体   繁体   English

GitHub-在不影响本地存储库的情况下删除推送的提交

[英]GitHub - Remove pushed commits without affecting local repository

What is the best way to remove commits from GitHub without affecting my local repositories since i made some commits that i wish to keep? 自从我做了一些我希望保留的提交以来,从GitHub删除提交而不影响我的本地存储库的最佳方法是什么?

Github repository has two wrong commits that i desire to remove while keeping the commits on my local repository. Github存储库有两个错误的提交,我希望将其删除,同时将提交保留在本地存储库中。

Assuming the current repository state is this: 假设当前存储库状态为:

server:         A---B---C---D
                            ^master

workstation:    A---B---C---D
                            ^HEAD
                            ^master
                            ^origin/master

And the desired state is this: 所需的状态是这样的:

server:         A---B
                    ^master

workstation:    A---B---C---D
                            ^HEAD
                            ^master
                    ^origin/master

Then what you can do to get there is this: 然后,您可以执行以下操作:

$ git push --force origin bbbbbbbb:master

where bbbbbbbb is the commit hash of B. 其中bbbbbbbb是B的提交哈希。

Notes: 笔记:

  • As with all --force , be careful. 与所有--force ,要小心。 You can get yourself into a place that's difficult to come out of. 您可以将自己带到一个难以脱身的地方。
  • Make sure all your team members know what you're doing. 确保所有团队成员都知道您在做什么。 They may inadvertently push C and D right back into the repository if they don't update their own repository correctly after you push. 如果您在推送后没有正确更新自己的存储库,他们可能会无意间将C和D直接推回到存储库中。
  • If any other tags/branches point to commits C and D, they'll remain accessible through there. 如果其他任何标记/分支指向提交C和D,则它们仍可通过此处访问。
  • Commits C and D and all changes in them may not be instantly deleted. 提交C和D,它们中的所有更改可能不会立即删除。 They will be removed in a garbage collection pass at an undefined moment in time. 它们将在未定义的时间通过垃圾收集传递删除。

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

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