How is the conflict

I am just testing git to see if I can use it for my work. I ran into a problem that seems small but can become real with real code. My file looks like this: text.txt 1 2 3 4 I have a local branch "branch1" and fixed changes in both the branch and the master. In master, I changed the first line in the branch to the second. So the diff for the wizard looks like this:

+1 master
 2
 3
 4

For a branch, this is:

 1
-2
+2b1
 3
 4

Running git merge branch 1 resolved in conflict:

<<<<<<< HEAD
1 master
2
=======
1
2b1
>>>>>>> branch1
3
4

I know this can be easily resolved. But how is this a conflict, anyway. Can't git combine this?

+3
source share
2 answers

A couple of comments:

  • -, :

    warning: Cannot merge binary files: afile.txt (HEAD vs. abranch)
  • , "" , , , , master, :

    git rebase -C0 master

master.

, rebase, ( ", " ), .

git :

-C<n>

<n> .
, .
.


(, PowerShell, Git1.6.5.1, Xp)

genfile.bat

echo hello, World %1 > afile.txt
echo hello, World %2 >> afile.txt
echo hello, World 3 >> afile.txt
echo hello, World 4 >> afile.txt
echo hello, World 5 >> afile.txt

:

PS D:\git\tests\mergeLines> git init m0
PS D:\git\tests\mergeLines> cd m0
PS D:\[...]\m0> D:\git\tests\mergeLines\genfile.bat 1 2
PS D:\[...]\m0> git add -A
PS D:\[...]\m0> git ci -m "afile to be modified concurrently"

:

hello, World 1
hello, World 2
hello, World 3
hello, World 4
hello, World 5

PS D:\[...]\m0> git co -b abranch
PS D:\[...]\m0> D:\git\tests\mergeLines\genfile.bat 1 2_modified
PS D:\[...]\m0> git ci -a -m "afile modified in abranch"

:

hello, World 1
hello, World 2_modified
hello, World 3
hello, World 4
hello, World 5

master

PS D:\[...]\m0> git co master
PS D:\[...]\m0> D:\git\tests\mergeLines\genfile.bat 1_master 2
PS D:\[...]\m0> git ci -a -m "afile modified in master"

:

hello, World 1_master
hello, World 2
hello, World 3
hello, World 4
hello, World 5

, (.. abranch master)

PS D:\[...]\m0> cd ..
PS D:\git\tests\mergeLines> git clone m0 m1
PS D:\git\tests\mergeLines> cd m1
PS D:\[...]\m1> git co -b abranch origin/abranch
PS D:\[...]\m1> git co master
PS D:\[...]\m1> git merge abranch

:

Auto-merging afile.txt
CONFLICT (content): Merge conflict in afile.txt
Automatic merge failed; fix conflicts and then commit the result.

PS D:\[...]\m1> type afile.txt
<<<<<<< HEAD
hello, World 1_master 
hello, World 2 
=======
hello, World 1 
hello, World 2_modified 
>>>>>>> abranch
hello, World 3 
hello, World 4 
hello, World 5 

, , abranch master, :

PS D:\[...]\m1> cd ..
PS D:\git\tests\mergeLines> git clone m0 m2
PS D:\git\tests\mergeLines> cd m2
PS D:\[...]\m2> git co -b abranch origin/abranch
PS D:\[...]\m2> git rebase -C0 master

:

hello, World 1_master
hello, World 2_modified
hello, World 3
hello, World 4
hello, World 5

master abranch, .

PS D:\git\tests\mergeLines\m2> git co master
Switched to branch 'master'
PS D:\git\tests\mergeLines\m2> git merge abranch
Updating c8f48b4..8bee1d2
Fast forward
 afile.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
+5

, , , . : "1/2" "1 /2" "1/2/3" "1/2b1/3".

"" , , , . "1/2/3", "1 /2/3".

, , , , - , .

+4

Source: https://habr.com/ru/post/1723208/


All Articles