Thank you for this reaction. I can follow what you write and it is clear to me that by doing what you did, the situation I described can emerge. But the thing is: there were no deletes. Head does not contain certain lines that the branch to merge in does. So the lines in the branch to merge are just new- that's all! Any ideas?
Hans Op dinsdag 24 juli 2012 13:31:54 UTC+2 schreef Antony het volgende: > > > > On Tuesday, 24 July 2012 09:36:41 UTC+1, Hans Zorn wrote: >> >> After doing a merge of 2 branches in a Delphi project I get some merge >> conflicts. >> Some I understand are clearly conflicts as they are simply adverse. But >> many look like this example: >> >> <<<<<<< HEAD >> ======= >> + Button13: TButton; >> + IBCustomerISACTIVE: TIBStringField; >> + DBCheckBox5: TDBCheckBox; >> + DBCheckBox6: TDBCheckBox; >> + IBStationISACTIVE: TIBStringField; >> + IBAccountISACTIVE: TIBStringField; >> + DBCheckBox7: TDBCheckBox; >> + IBCustomerSHOWPRICE: TIBStringField; >> + DBCheckBox8: TDBCheckBox; >> >>>>>>> 51ae5a7d04e585b6785b4c5d0e84114298408a27 >> >> So my question is: what is conflicting here? Why does git not just copy >> the added lines of the second branch into HEAD? >> >> This happens if one side of the merge removed some lines, while the other > side changed them. Let's set up an example: > > Create a new file with 3 lines > > $ echo -e "initial line 1\ninitial line 2\ninitial line 3" > file > $ cat file > initial line 1 > initial line 2 > initial line 3 > $ git add file && git commit -m "Add initial lines" > [master (root-commit) 2e3cd57] Add initial lines > 1 file changed, 3 insertions(+) > create mode 100644 file > > Then we'll branch, and modify these lines > > $ git checkout -b branch > Switched to a new branch 'branch' > $ echo -e "modified line 1\nmodified line 2\nmodified line 3" > file > $ cat file > modified line 1 > modified line 2 > modified line 3 > $ git commit -am "Add modified lines" > [branch 9c42865] Add modified lines > 1 file changed, 3 insertions(+), 3 deletions(-) > > Meanwhile on master, we'll remove those lines > > $ git checkout master > Switched to branch 'master' > $ cat /dev/null > file > $ git commit -am "Remove lines from file" > [master f008f71] Remove lines from file > 1 file changed, 3 deletions(-) > > Then we'll try and merge the two versions together > > $ git merge branch > Auto-merging file > CONFLICT (content): Merge conflict in file > Automatic merge failed; fix conflicts and then commit the result. > $ cat file > <<<<<<< HEAD > ======= > modified line 1 > modified line 2 > modified line 3 > >>>>>>> branch > > As you can see, the HEAD side removed the lines (which is shown by the > HEAD section being empty), while the branch side modified the lines, which > is also shown. > It might be easier to see if we use the 'diff3' style conflict markers, > which also shows the original version (see diff.conflictstyle in man > git-config). > > $ git merge --abort > $ git -c merge.conflictstyle=diff3 merge branch > Auto-merging file > CONFLICT (content): Merge conflict in file > Automatic merge failed; fix conflicts and then commit the result. > $ cat file > <<<<<<< HEAD > ||||||| merged common ancestors > initial line 1 > initial line 2 > initial line 3 > ======= > modified line 1 > modified line 2 > modified line 3 > >>>>>>> branch > > Here, git shows you the original lines (between the |||| and ====), so > it's easier to see the modifications that each branch did to the original. > > Hope that clears things up, > Antony > > > > -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To view this discussion on the web visit https://groups.google.com/d/msg/git-users/-/z3favmoFfdYJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/git-users?hl=en.
