login
Header Space

 
 

Git merge strategy too conservative?

November 26, 2007 - 1:55am
Submitted by Anonymous on November 26, 2007 - 1:55am.
Applications and Utilities

I'm new to git and merging in general, and I'm very humbly bringing a question to the forum that I haven't been able to answer myself. Presented here is a very contrived example reduced from an actual issue I encountered: please the consider directory project containing a single file example. The contents of the file:

$ cat example
hello
goodbye

The folder and its file are the contents of my initial import.

$ git init
Initialized empty Git repository in .git/
$ git add example
$ git commit -m "initial import."
Created initial commit 2ff99c...

Then I did the following:

$ git checkout -b mybranch
Switched to a new branch "mybranch"
$ sed -i 's/hello/hello world/' example
$ git commit -a -m "hello world."
Created commit 67bc55a...

$ cat example
hello world
goodbye

$ git checkout master
Switched to branch "master"
$ sed -i 's/goodbye/goodbye world/' example
$ git commit -a -m "goodbye world."
Created commit c0bd32a...

$ cat example
hello
goodbye world

When I call git merge mybranch, I'm expecting:

$ cat example
hello world
goodbye world

But I ended up with a merge conflict instead.

I'm trying to think of a scenario where I'd want merge to highlight this conflict, but so far haven't able to.

Am I using git correctly? Or are conflicts unavoidable in two-way merges if the heads contain different modifications on the same file?

Thank you for reading through, and be gracious especially if the answer is really obvious.

Cheers

Generally, when speaking of

November 26, 2007 - 5:36am

Generally, when speaking of actual code, you really do want the RCS to flag this as a conflict, because changes to two subsequent lines are likely to break.

git probably would merge it transparently if the changes were set apart by a few lines.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary