andrzej1_1
andrzej1_1

Reputation: 1193

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.

Upvotes: 10

Views: 5141

Answers (2)

CB Bailey
CB Bailey

Reputation: 791759

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

Upvotes: 9

Ilion
Ilion

Reputation: 6872

The conflict appears to show that in one instance the line is specifically empty but in another you've added the two lines. Something has happened so that there's not an easy line from one commit to the other.

It's a bit difficult to say exactly how this conflict has come about without browsing you're git log. To help you see where things have diverged you can try one of the following two commands:

git log --graph --oneline --decorate

git log --all

The difference is the second one will show commits that the second will show branches not related to the current HEAD.

I'd suspect you edited the file somehow on both branches, maybe not realizing it.

Upvotes: 0

Related Questions