Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Weird conflict with nothing

I created new branch and I added few lines in one file. After that I want to merge it to master but git is showing conflict:

<<<<<<< destination:ad27cc8d6bb445757c38541eb57ea7d3cba944b3
=======
foo
bar
>>>>>>> source:385f662b3668c9173dd757e850ceba54cfd05560

I don't understand why it is conflict, if I only add few lines. So, what is wrong?

SOLVED:

I swaped position of few lines and Bitbucket didn't show conflict. After merging in Git Bash I saw and resolved this.

like image 211
andrzej1_1 Avatar asked Aug 13 '14 07:08

andrzej1_1


Video Answer


1 Answers

I can reproduce your conflict as follows:

$ git init
$ echo a >test
$ git add test
$ git commit -m msg
[master (root-commit) eac86cc] msg
 1 file changed, 1 insertion(+)
 create mode 100644 test
$ git checkout -b source
Switched to a new branch 'source'
$ printf 'foo\nbar\n' >test
$ git commit -am source
[source 9f22aa2] source
 1 file changed, 2 insertions(+), 1 deletion(-)
$ git checkout master
Switched to branch 'master'
$ >test
$ git commit -am destination
[master 45e3e19] destination
 1 file changed, 1 deletion(-)
$ git -c merge.conflictstyle=merge merge source
Auto-merging test
CONFLICT (content): Merge conflict in test
Automatic merge failed; fix conflicts and then commit the result.
$ cat test
<<<<<<< HEAD
=======
foo
bar
>>>>>>> source

What has happened is that one branch has changed a to foo/bar and the other branch has deleted a. It's impossible to tell from the simple merge style conflict markers but if you use merge.conflictstyle=diff3 then you'd see something like the output below which makes it obvious why there was a conflict.

Obviously, your conflict is likely to be different in the details.

<<<<<<< HEAD
||||||| merged common ancestors
a
=======
foo
bar
>>>>>>> source
like image 156
CB Bailey Avatar answered Oct 20 '22 16:10

CB Bailey