简体   繁体   English

强制推送到公共远程分支机构安全吗?

[英]Is it safe to force push to a public remote branch?

I made some commits on my local feature branch and decided to push it to the public repository for back-up purposes only. 我在本地功能分支上进行了一些提交,决定将其推送到公共存储库中仅出于备份目的。 Is it safe to rebase some commits and force (with lease?) push them to a public repository? 将某些提交重新设置为基准并强制(带有租赁?)将其推送到公共存储库是否安全? In this case I am the only person working on this branch but would it still be possible to force push when there were working more people on this branch? 在这种情况下,我是该分支机构中唯一的工作人员,但是当该分支机构中有更多工作人员时,是否仍然可以强制推动?

In a nutshell: 简而言之:

Don't do it. 不要这样 Not without talking it over first. 并非没有先讨论一下。

If Git is telling you that it won't accept your push because the refs don't line up, Git is doing its job by attempting to protect the integrity of your repository. 如果Git告诉您由于裁判未排队而不会接受您的推送,则Git会通过尝试保护存储库的完整性来完成其工作。

That is, if you've got history on your local branch that Git doesn't agree with, Git won't accept it. 就是说,如果您在本地分支机构上有Git不一致的历史记录,则Git不会接受。

Once you force-push that branch, Git assumes you know what you're doing and will let you push the branch. 一旦强行按下该分支,Git就会假设您知道自己在做什么,并将让您推动该分支。

This has an adverse effect on anyone else using the branch: 这会对使用分支的其他任何人产生不利影响:

  • History has been rewritten, so when they attempt to get new work or attempt to integrate their work upstream, they have to rewrite their own local history to match upstream. 历史记录已被重写,因此当他们尝试获取新作品或尝试在上游整合他们的作品时,他们必须重写自己的本地历史记录以匹配上游作品。
  • Commits could be lost in this manner. 提交可能会以这种方式丢失。 Since you're rewriting history with a rebase, this is a scenario which is very likely to happen. 由于您要使用基准库来重写历史记录,因此这种情况极有可能发生。
  • Without any prior communication, you will have caused confusion among the maintainers, and this will lead to slowdowns in development. 没有任何事先沟通,您将在维护人员之间造成混乱,这将导致开发速度降低。

If it's literally just you then it's fine, but if there's any chance of anyone else using your code base, you have to take precautions. 如果从字面上看只是您,那很好,但是如果其他任何人有可能使用您的代码库,则必须采取预防措施。

Is it safe to rebase some commits and force (with lease?) push them to a public repository? 将某些提交重新设置为基准并强制(带有租赁?)将其推送到公共存储库是否安全?

If you are sure that you only work in this feature branch, indeed, you could what you want and indeed, rebase and force push to sync is perhaps the better solution! 如果您确定只在此功能分支中工作,那么确实可以,您想要的确实可以,并且变基并强制执行同步可能是更好的解决方案!

In this case I am the only person working on this branch but would it still be possible to force push when there were working more people on this branch? 在这种情况下,我是该分支机构中唯一的工作人员,但是当该分支机构中有更多工作人员时,是否仍然可以强制推动?

You could still do force push in some rare cases where you and your team decide that there is some added value compare to keeping history as it is. 在某些罕见的情况下,您和您的团队仍然认为保留历史记录会带来一些附加值,您仍然可以强制执行。 But expect these very specific case, everybody agrees that it's better to never rewrite the history of a shared branch pushed. 但是期待这些非常具体的情况,每个人都同意最好不要重写推送的共享分支的历史记录。 Because it will annoy all the other developers and will often require some more time and more advanced knowledge (git rebase -i) to sync its work with a remote with a history modified (force pushed). 因为它将使所有其他开发人员烦恼,并且通常需要更多的时间和更高级的知识(git rebase -i)才能将其工作与修改了历史记录的远程同步(强制按下)。

Like a lot of things in git, that's not the tool that will prevent you to do some things but rather a team convention because you find something better... 就像git中的很多事情一样,这不是阻止您执行某些操作的工具,而是团队惯例,因为您会发现更好的东西...

Ps: and yes, if you what to force push, do it always with '--force-with-lease' to prevent losing someone else history that you didn't see! 附:是的,如果您要强制执行什么操作,请始终使用“ --force-with-lease”来执行此操作,以防止丢失其他人没有看到的历史记录!

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

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