简体   繁体   English

如何使用master的更改更新远程分支

[英]How do I update a remote branch with changes from master

I've done a fair bit of research/practices on rebasing and merging our remote branches but I am unable to find a solution that ultimately doesn't result in duplicate commits or a non-fast forward push of the remote branch. 我已经对重新建立和合并我们的远程分支机构做了很多研究/实践,但是我找不到能够最终不会导致重复提交或远程分支机构的非快速推进的解决方案。 Here's what I'm trying to do. 这就是我想要做的。

We have two branches, master (tracking origin/master ) and hebe (tracking origin/hebe ). 我们有两个分支, master (跟踪origin/master )和hebe (跟踪origin/hebe )。 hebe was branched off of master appropriately a month ago. 一个月前, hebe适当地脱离了master There are several developers working on both branches daily. 每天都有两个开发商在这两个分支上工作。

master is continuing to be maintained and has several bug fixes in common code that should be reflected/updated in the hebe branch. master仍将继续维护,并在hebe分支中反映/更新了一些常见代码中的错误修复。 However none of the new code in hebe should make its way into master 但是, hebe任何新代码都不应该成为master

I've tried: 我试过了:

git rebase master hebe

Which seemed from the log to be exactly what we wanted, hebe commits were on top of the latest master , however when I attempt to push hebe it resulted in a warning of a non-fast forward push of origin/hebe . 从日志来看,这正是我们想要的,但是hebe提交位于最新的master之上,但是当我尝试推动hebe它会发出警告,指出origin/hebe不能快速推进。

Or perhaps we are approaching this from the wrong direction and submodules would be the appropriate solution? 还是我们从错误的方向进行处理,而子模块将是合适的解决方案?

You should only rebase in very very very rare cases branches which are already pushed and shared with others since you rewrite the history and thus change the sha's of the commits. 您仅应在非常非常罕见的情况下重新设置分支,因为重写了历史记录并因此更改了提交的密码,分支已经被推送并与他人共享。 This results in your mentioned duplicate commits because a different sha means a different commit for git. 这导致您提到重复的提交,因为不同的sha意味着git的不同提交。
In your case it is better to merge the master with 在您的情况下,最好将母版与

$ git checkout hebe
$ git merge master
$ git push origin hebe

With this you merge all changes from master into hebe but nothing gets back to master and all shas stay the same. 这样,您就可以将所有更改从大师合并到hebe但是什么也回到不了大师,所有阴影都保持不变。 Merging will create an so called merge commit instead (if no fast-forward merge is possible). 合并将创建一个所谓的合并提交(如果无法进行快速合并)。

Because it is so important and leads to so many confusion, I have to say this again on the end: Never rebase already shared branches unless you are absolutely sure what you are doing. 因为它是如此重要,并且会引起很多混乱,所以我必须在最后再说一遍:除非您完全确定自己在做什么,否则切勿为已经共享的分支重新设置基础。

I deeply recommend reading the third chapter of the following (free online available) book http://git-scm.com/book to get a better understanding of how merging/rebasing works 我强烈建议阅读以下(免费的在线可用)书籍的第三章http://git-scm.com/book ,以更好地了解合并/重新设置的工作方式

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

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