I have a file with one line in it. I create a branch and add a second line to the same file. Save and commit to the branch. I switch back to the master. And add a different, second line to the file. Save and commit to the master. So there's now 3 unique lines in total.
If I now try and merge the branch back to the master, it suffers a merge conflict.
Why cant Git simple merge each line, one after the other?
My attempt at merge behaves something like this:
PS D:\dev\testing\test1> git merge newbranch
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.
PS D:\dev\testing\test1> git diff
diff --cc hello.txt
index 726eeaf,e48d31a..0000000
--- a/hello.txt
+++ b/hello.txt
@@@ -1,2 -1,2 +1,6 @@@
This is the first line.
- New line added by master.
-Added a line in newbranch.
++<<<<<<< HEAD
++New line added by master.
++=======
++Added a line in newbranch.
++>>>>>>> newbranch
Is there a way to make it slot lines in automatically, one after the other?
Let's say the file branch A looks like:
First line
Branch A's second line
And branch B looks like:
First line
Branch B's second line
When you merge, there are two different ways to resolve it. Here's one way:
First line
Branch A's second line
Branch B's second line
Here's another way:
First line
Branch B's second line
Branch A's second line
Git has no idea which one of those two options you prefer, or if either are even acceptable merges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With