Commit only stage/index, ignoring conflicts

719 views Asked by At

I have a huge commit, which I cherry-picked. The pick now creates a sum of conflicts (in working-tree). Now I would like to commit all the staged (successfully merged) changes without having to resolve all conflicts.

Naively I always thought, commit would only work on the stage, but when I try, I get the message, that I cannot commit without resolving the conflicts.

Can someone explain to me what is going on and how I could fix it.

1

There are 1 answers

2
oradwell On

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.