简体   繁体   English

什么时候推送到git的原点

[英]When to push to origin in git

I have a feeling this has been asked before but I can't find it in SO. 我有一种感觉以前曾被问过,但我找不到它。
When is the right moment to push a topic branch to origin? 什么时候将主题分支推向原点?

I am asking this because we have a workflow at work where we end up git push --force quite often. 我问这个是因为我们有一个工作流程,我们最终经常使用git push --force The workflow is to rebase onto master when our topic branch has fallen behind, but because we push our topic branches early and often, that means that this rebase onto master requires a force push to publish the new, rebased topic branch. 当我们的主题分支落后时,工作流程将重新绑定到主服务器上,但是因为我们提前和经常推送主题分支,这意味着这个主服务器需要强制推送来发布新的,重新定义的主题分支。

Now I am thinking that the root reason to need this ugly and dangerous force is because we are pushing the topic branch often (one reason being to backup your work, another to have your work accessible in case you miss work or something), maybe this is wrong?? 现在我认为需要这种丑陋和危险的力量的根本原因是因为我们经常推动主题分支(一个原因是备份你的工作,另一个原因是为了让你的工作可以访问,以防你错过工作或其他事情),也许这是错的?? so I am wondering, when is the best moment to push a branch since normally once it's pushed, a rebase basically becomes forbidden, yet we still do it. 所以我想知道,什么时候推动分支是最好的时刻,因为正常情况下,一旦它被推动,基本上就会被禁止,但我们仍然会这样做。
Should the topic branch push only happen once the branch is ready to be merged? 是否只有在分支准备好合并后才会发生主题分支推送? but then you risk losing your work if your hard disk dies or having your work trapped in your machine 但如果您的硬盘死机或您的工作被困在您的机器中,您将面临失去工作的风险

If it's important, we are following a pull-request model like github (BUT without forking) where the merge of topic to master happens on a repo manager on a central server, hence why we need to push topic branches 如果它很重要,我们正在遵循像github这样的拉取请求模型(BUT without forking),其中主题与master的合并发生在中央服务器上的repo管理器上,因此我们需要推送主题分支

Don't think of --force as meaning "You shouldn't do this." 不要认为--force意思是“你不应该这样做”。 Think of it more as meaning "You shouldn't do this unless you know what you're doing." 把它想象成“你不应该这样做,除非你知道你在做什么。”

You do know what you're doing, and you're not causing anyone any trouble, so --force isn't really a problem. 你确实知道自己在做什么,而且没有给任何人带来任何麻烦,所以--force并不是真正的问题。

Remember that Git commits originate on someone else's machine before they reach the remote repo. 请记住,Git提交源自其他人的机器,然后才能到达远程仓库。 So by pushing with --force , you're not likely to be destroying work, because someone else already had that work on his/her machine. 因此,通过使用--force推动,您不可能破坏工作,因为其他人已经在他/她的机器上完成了这项工作。

I guess it comes down to this: You have the idea that --force is ugly and dangerous. 我想这归结为:你有一个想法 - --force是丑陋和危险的。 But why? 但为什么? Sure, it shouldn't be taken lightly. 当然,不应掉以轻心。 But it's a tool in your toolbox, and you know how to use it correctly. 但它是您工具箱中的工具,您知道如何正确使用它。 You could avoid ever incorporating the changes from master until your topic branch is done (or at least nearly done). 您可以避免在主题分支完成之前(或者至少差不多完成)将master中的更改合并。 Or you could each push to a private repo, which would still let you back up without having to worry about anyone else when force-pushing. 或者你们每个人都可以推送到一个私人仓库,它仍然可以让你备份,而不必在强迫推动时担心其他任何人。

But if using --force works, why worry about it? 但是如果使用--force有效,为什么要担心呢?

That depends on your particular workflow. 这取决于您的特定工作流程。 I keep my origins completely up to date at all time (mostly for my own use, few external onlookers, next to none interested in day-to-day or experimental changes/topic branches). 我始终保持最新状态(主要是供我自己使用,很少有外部旁观者,对日常或实验性更改/主题分支感兴趣)。 You might want to restrict publication of experimental branches until they are ripe (or not liable to be axed anymore ;-), or even never publish them. 您可能希望限制实验分支的发布,直到它们成熟(或不再容易被砍掉;-),或者甚至从不发布它们。

If you work together with a group of people, you should agree on (at least rough) policy on this. 如果您与一群人一起工作,您应该就此达成一致(至少是粗略的)政策。

You might want to search for suggestions on git workflows, there are several around. 您可能想要在git工作流上搜索建议,周围有几个。 Not that you'll need to follow any of them, but the discussions on when to use each (and why) should clear up the matter. 并不是说您需要遵循它们中的任何一个,但关于何时使用每个(以及为什么)的讨论应该澄清问题。

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

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