Couple of comments:
first, such a small example would never be merged anyway:
warning: Cannot merge binary files: afile.txt (HEAD vs. abranch)
then, if you have many "small" merge conflicts which you know should be resolved independently of the context, you could try rebasing first your branch on top of master
, ignoring the context:
git rebase -C0 master
and then merge your branch into master
.
This is generally not a good idea to ignore all context for a rebase, but if you are certain about your modifications (as in "modifications needing no context at all"), it will work.
From git rebase man page:
-C<n>
Ensure at least <n>
lines of surrounding context match before and after each change.
When fewer lines of surrounding context exist they all must match.
By default no context is ever ignored.
You can test it easily enough (here in a PowerShell session, with Git1.6.5.1, on Xp)
First create a small bat utility 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
then create a repo and add a file:
PS D:git estsmergeLines> git init m0
PS D:git estsmergeLines> cd m0
PS D:[...]m0> D:git estsmergeLinesgenfile.bat 1 2
PS D:[...]m0> git add -A
PS D:[...]m0> git ci -m "afile to be modified concurrently"
Your file looks like this:
hello, World 1
hello, World 2
hello, World 3
hello, World 4
hello, World 5
Modify it in a branch
PS D:[...]m0> git co -b abranch
PS D:[...]m0> D:git estsmergeLinesgenfile.bat 1 2_modified
PS D:[...]m0> git ci -a -m "afile modified in abranch"
You will have:
hello, World 1
hello, World 2_modified
hello, World 3
hello, World 4
hello, World 5
Then modify it in master
PS D:[...]m0> git co master
PS D:[...]m0> D:git estsmergeLinesgenfile.bat 1_master 2
PS D:[...]m0> git ci -a -m "afile modified in master"
Which gives you:
hello, World 1_master
hello, World 2
hello, World 3
hello, World 4
hello, World 5
Clone that repo for a first experiment (i.e.: a merge of abranch
into master
)
PS D:[...]m0> cd ..
PS D:git estsmergeLines> git clone m0 m1
PS D:git estsmergeLines> cd m1
PS D:[...]m1> git co -b abranch origin/abranch
PS D:[...]m1> git co master
PS D:[...]m1> git merge abranch
That gives you a conflict:
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
Clone the first repo again, this time to rebase first abranch
on top of master
, with no context:
PS D:[...]m1> cd ..
PS D:git estsmergeLines> git clone m0 m2
PS D:git estsmergeLines> cd m2
PS D:[...]m2> git co -b abranch origin/abranch
PS D:[...]m2> git rebase -C0 master
Your file is silently merged:
hello, World 1_master
hello, World 2_modified
hello, World 3
hello, World 4
hello, World 5
Off course, if you switch back to master
and now merge abranch
, the result will be a fast-forward merge.
PS D:git estsmergeLinesm2> git co master
Switched to branch master
PS D:git estsmergeLinesm2> git merge abranch
Updating c8f48b4..8bee1d2
Fast forward
afile.txt | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)