0

我有一个巨大的承诺,我选择了它。选择现在创建了一个冲突总和(在工作树中)。现在我想提交所有分阶段(成功合并)的更改,而不必解决所有冲突。

天真地我一直认为,commit 只会在舞台上起作用,但是当我尝试时,我得到的信息是,如果不解决冲突,我就无法提交。

有人可以向我解释发生了什么以及如何解决它。

4

1 回答 1

0

You have to resolve the conflicts as conflicts only happen when git cannot automatically merge the branches. They mostly occur when the same line was modified in 2 separate commits.

Example

master branch:

L1. git
L2. is
L3. awesome

branch A and B was branched off from master

Commit x applied on branch A

L1. git
L2. is not
L3. awesome

Diff

 git
-is
+is not
 awesome

Commit y applied on branch B

L1. git
L2. isn't
L3. awesome

Diff

 git
-is
+isn't
 awesome

When you merge branch A and try to merge branch B afterwards into master, git cannot decide what to put for L2. Whilst resolving the conflicts you have to make that decision.

How to resolve the conflicts

Easiest way to resolve is selecting which version of the file you want to keep.

To select the version of the file that is on the current branch (HEAD)

git checkout --ours <filename>

To select the version of the file that is on the other branch (the branch that you pulled / cherry-picked from. possibly the remote branch):

git checkout --theirs <filename>

Or you can edit the files one by one and removing the conflict markers (<<<<<<<, =======, >>>>>>>) and picking which version to use

Afterwards you need to mark them as resolved by doing:

git add <filename>

Tip: You can use . as the filename to select all the files under the current directory.

于 2014-11-12T11:56:39.090 回答