当我从另一个分支中挑选提交,然后尝试合并它。如果 已经应用了更多更改我有合并冲突。
一个很好的例子,就是我遵循'gitflow'的方式来做git的陈词滥调 (掌握,开发,功能/错误修复,修补程序)。以下是步骤:
bugfix
合并到develop
develop
bugfix
并将其作为hotfix
应用到master
master
合并回develop
,我会发生合并冲突。bugfix
合并提交,那么合并master
(从而创建这个
“中间”合并),然后将此“中间”合并合并到develop
一切正常,没有任何冲突。如果之后没有发生变化,git会如何计算出樱桃选择。但如果更多 添加了更改,这是git的世界末日。
这是我的问题的ascii架构C'是挑选的C:
(键:✔=没有冲突,✘=冲突)
+-------------------->✘ <--+
| |
| |
| ✔<--------+ |
| ^ | |
| | +-+--+
| | | M2 +<-----+
| | +-+--+ |
| + ^ +-+-+
| +----------->✔<--------+ | | D |
| | | | +-+-+
+-+-++ +-+--+ ^
| Ma +<----+ +---->+ M1 +------+
+-+--+ | | +-^--+
^ +-+--+ +-+-+ |
| | C' | | C | |
| +-+--+ +-+-+ |
| ^ ^ |
| | | |
| +-+--+ +-+-+ |
| | B' | | B | |
| +-+--+ +-+-+ |
| ^ ^ |
+-+--+ | | |
| A +-----+---------+-------+
+-+--+ | | |
| | | |
| | | |
+ + + +
Master Cherry- Bugfix Develop
Picked
Hotfix
这是我创建这种情况的脚本:
git init
echo -e "foo\nbar\nbaz\nqux\nquux" > file
git add file
git commit -m "Initial commit"
git checkout -b develop
git branch second-feature
git checkout -b first-feature
echo -e "foo1\nbar\nbaz\nqux\nquux" > file
git commit -m "First feature" file
git checkout develop
git merge --no-ff -m "Merge first feature" first-feature
git checkout second-feature
echo -e "foo\nbar\nbaz2\nqux\nquux" > file
git commit -m "Second feature" file
git checkout develop
git merge --no-ff -m "Merge second feature" second-feature
git tag before-bugfix
git checkout -b bugfix
echo -e "foo1\nbar\nbaz2\nqux\nquux1" > file
git commit -m "Bugfix (part I)" file
echo -e "foo1\nbar\nbaz2\nqux\nquux2" > file
git commit -m "Bugfix (part II)" file
git checkout develop
git merge --no-ff -m "Merge bugfix" bugfix
git checkout -b third-feature
echo -e "foo1\nbar\baz2\nqux\nquux3" > file
git commit -m "Third feature" file
git checkout develop
git merge --no-ff -m "Third feature" third-feature
git checkout master
git cherry-pick -x before-bugfix..bugfix
如果我这样做,我会:
$ git checkout develop
$ git merge --no-ff master
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
如果我这样做,我会:
$ git checkout -b new-master bugfix
$ git merge --no-ff -m "In-between Merge" master
Merge made by the 'recursive' strategy.
$ git merge --no-ff -m "Merge master" new-master
Already up-to-date!
Merge made by the 'recursive' strategy.
有没有办法在一次合并中解决这个问题而没有任何冲突?
我尝试了不同的合并startegies,但它没有用。我试图合并主人和 在修复bugfix的同时,我仍然会遇到冲突。
答案 0 :(得分:0)
为了做你期望的事情,git必须跟踪合并分支的整个历史记录,以识别等效提交并跳过它。它不会这样做,它只使用历史记录中的3个提交:父母和&#34;合并基础&#34; - 父母的共同祖先。
如果您愿意,可以指导它:
git checkout -b master_with_develop master
develop
develop
develop
并合并master_with_develop
- 它会快进(您也可以将其标记为--no-ff
以创建显式合并提交)您可以查看尝试自动执行上述步骤的git-imerge工具