模拟GIT中的冲突 [英] Simulating Conflict in GIT
问题描述
我想在不提交的情况下切换分支时模拟git中的冲突.
I want to simulate conflict in git while switching braches without committing.
我有一个master分支,其中有一些提交的文件.
I have a master branch where I have a few files which are committed.
我创建了另一个分支,并修改了master分支中的文件.
I create anther branch and modify the files which are also present in the master branch.
我仍然没有在另一个分支中提交更改.
I still have not committted changes in the other branch.
但是当我尝试检出master分支时,它允许我做同样的事情.
But when I try to checkout the master branch It allows me to do the same.
我无法模拟冲突的情况.
I have not been able to simulate a conflicting scenario.
任何人都可以提供文件内容和同一文件的修改版本,这会导致冲突.
Can anyone give the file contents and the modified version of the same file which would cause a conflict.
推荐答案
合并在同一基础上发生的更改时会发生冲突,因此要生成冲突,您需要从上次提交之前的提交开始分支. master
:
Conflicts happen when merging changes that happened on a same base, so to generate a conflict you need to start a branch from a commit that happened before the last commit of master
:
如果您具有以下条件,则不会有冲突,因为修改是按顺序进行的:
If you have the following you can't get a conflict because modifications happened sequentially:
* branch tip
|
* master tip
|
* commit a
没有要合并的东西,它可以是分支,也可以是主.
There's nothing to merge, it's either branch or master.
相反,如果branch
和master
对文件的同一部分进行了修改,则以下内容将引发合并冲突,因为它们可能是不相关的:
On the contrary, the following will trigger a merge conflict if branch
and master
have made modifications on the same portion of a file, because they can be unrelated:
* branch tip
|
| * master tip
|/
* commit a
将branch
合并到master
中时会发生冲突,git无法说出是否要对branch
或master
或两者进行修改.
The conflict will happen on merging branch
into master
, git won't be able to say if you want to take the modification of branch
or of master
, or both.
这篇关于模拟GIT中的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!