2

I was hoping someone could explain a better way of doing this.

Let's say I have "master" and then two branches off of master - A and B.

Typically, when I'm done with branch A, I merge master into A, resolve any conflicts and then merge up to master.

I then checkout branch B and do the same...master into B and then back up to master.

However, after doing the merge with B, branch A is no longer current with master, which is what I want at this point. I usually just merge master down to A as that would be my branch and B is a co-workers.

This has been fine, but as we add employees and trying to sync all the branches gets annoying.

I know I could prune the branches but then the users working on the separate branches would have to branch off every time. I would like to just be able to "sync" all the branches once everything has been merged into master so the users can pick up in the morning on their same branch without skipping a beat.

Is there a way to do this?

4

1 回答 1

2

好吧,让我们形象化。这是您在进行任何合并之前的历史记录:

      O       A
     /
O - O - O     master
     \
      O - O   B

然后,您合并masterA合并回master

      O - O  A, master
     /   / 
O - O - O  
     \
      O - O  B

然后,您对B. 合并masterB

      O - O      A, master
     /   / \
O - O - O   \
     \       \
      O - O - O  B

然后将其合并回master

      O - O      A
     /   / \
O - O - O   \
     \       \
      O - O - O  B, master

如您所见,这样做会造成相当混乱。但是,要Amaster此处同步,只需将其合并即可。这将是一个快进,之后看起来像这样:

      O - O
     /   / \
O - O - O   \
     \       \
      O - O - O  A, B, master

或者

做你想做的更好的方法:只需将所有内容直接合并到 master 中。master如果你只是再次合并回来,你不需要合并到另一个分支。即使存在合并冲突,由于您无法推送合并冲突,在您完成并推送之前,没有人会注意到您正在分支 master 中工作。A直接合并到 master 将产生以下结果(与您的结果相同,但B指向其他地方):

        O           A
      /   \
O - O - O - O - O   master
     \        /
      O  -  O       B

但是,这使您没有A合并B。他们仍然指向一个旧的提交。因此,快进将它们合并到 master 中。这将使您的历史看起来像这样:

        O
      /   \
O - O - O - O - O   A, B, master
     \        /
      O  -  O

A当您现在一次又一次地提交某些内容B时,它们会有所不同并使历史看起来像这样:

        O         O    A
      /   \      /
O - O - O - O - O      master
     \        /  \
      O  -  O     O    B

这正是你想要的,对吧?

于 2013-09-19T08:03:10.057 回答