简体   繁体   English

git工作流程,并将更改从master合并到分支

[英]git workflow, and merging changes from master into branches

Having struggled with SVN I was told I should check out GIT, as the branches would be ideal for the workflow I am trying to achieve. 与SVN挣扎后,我被告知我应该签出GIT,因为分支对于我要实现的工作流程非常理想。 I have been muddling along and think I have the basics of GIT sorted now. 我一直在摸索,认为我现在已经整理了GIT的基础知识。

We basically have a central framework that some of our clients use, and I want to have a trunk / master and using branches as normal, for dev / trying stuff out, but I would also like to create branches for each client, so I could work on client specific changes to the code. 我们基本上有一些客户使用的中央框架,我想有一个主干/主节点,并像往常一样使用分支,以便进行开发/尝试,但是我也想为每个客户创建分支,所以我可以处理客户特定的代码更改。 These branches would always be a branch and never end up getting merged back into the trunk / master. 这些分支永远是分支,永远不会最终合并回主干/主节点。

The main thing I am trying to achieve is so that I can easily merge all changes FROM the trunk / master TO the various client branches, and I am getting confused with if I need to merge, or rebase. 我要实现的主要目的是使我可以轻松地合并从主干/主节点到各个客户端分支的所有更改,如果需要合并或重新设置基准,我会感到困惑。

So my question... Should I always be using rebase for this, and if so why? 所以我的问题是:我是否应该一直为此使用rebase?如果是,为什么? (because I want to keep the individual commits in each branch?) (因为我想在每个分支中保留单个提交?)

Edit So I create a repo, and in that repo I have say file.php with $x = 1 编辑所以我创建了一个仓库,在那个仓库中我说了file.php $x = 1

  • I commit that to master 我把那个交给主人
  • I create a branch called client1 我创建一个名为client1的分支
  • In client1 I add a new file and commit client1中,我添加一个新文件并提交
  • In client1 I change file.php so $x = 2 client1中,我更改了file.php,因此$x = 2

git log预合并

  • In master I make a change to file.php but its a new line, and $x remains $x = 1 master中,我对file.php进行了更改,但是换了一行,并且$ x仍然是$x = 1
  • In client1 I merge master and get a conflict on $x client1中,我合并master并在$x发生冲突

Is it because I am adding a new line to file.php adjacent to $x that it is causing the conflict? 是因为我在$x旁边的file.php中添加了新行,导致冲突?

You should merge. 你应该合并。 Rebasing will take all of the changes on master since the branch diverged from master and recreate them on top of the branch. 自分支分支脱离主分支以来, 重新调整将对主分支进行所有更改,并在分支顶部重新创建它们。 This means that each commit on master will be duplicated for every client branch you are tracking. 这意味着,对于要跟踪的每个客户端分支,master上的每个提交都将重复。

Merging is semantically what you're doing. 从语义上来说,合并就是您正在做的事情。 The resulting commit graph will look much nicer, and Git will have an easier time performing merges since, after each merge, the history of master will become part of the branch's own history -- Git will only have to consider the commits on master since the last merge, instead of reconsidering every commit on master . 生成的提交图看起来会更好,并且Git执行合并的时间会更容易,因为在每次合并之后,master的历史记录将成为分支自身历史的一部分-Git只需要考虑master上的提交,因为最后合并,而不是重新考虑master上的每个提交

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

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