Automatic merge failed; fix conflicts and then commit the result.
I was faced with “a merge conflict”, and managed to troubleshoote it. Following commands are what I typed right before the conflict.
$ git add lists/templates/home.html
$ git commit -m “manage.py test passed” lists/templates/home.html
$ git branch
chapter1
chapter2-feature-unittest
chapter2-feature-unittest-exception
chapter3-testing-simple-hp-with-unittests
* chapter4-refactoring
chapter4-refactoring-from-No00973
chapter4-refactoring-from-No01175
chapter4-refactoring-from-No01278
chapter5-saving-user-input
chapter5-saving-user-input-from-No01491
chapter5-saving-user-input-from-No01526
master
$ git push origin chapter4-refactoring
$ git checkout chapter5-saving-user-input
$ git merge chapter4-refactoring
Auto-merging lists/templates/home.html
CONFLICT (content): Merge conflict in lists/templates/home.html
Automatic merge failed; fix conflicts and then commit the result.
I tried to troubleshoot it as I refered a following page.
sources;
“Resolving a merge conflict using the command line”
1st step is to see the files affected by the merge conflict.
This target file is, for convenience, set the font style as bold and as italic.
$ git status
You have unmerged paths.
(fix conflicts and run “git commit”)
Unmerged paths:
(use “git add <file>…” to mark resolution)
both modified: lists/templates/home.html
no changes added to commit (use “git add” and/or “git commit -a”)
If you would like to see for more details, type “git diff”.
$ git diff
diff — cc lists/templates/home.html
index b0dff8b,c258350..0000000
mode 100644,100644..100755
— — a/lists/templates/home.html
+++ b/lists/templates/home.html
@@@ -8,16 -8,8 +8,21 @@@
</head>
<body>
<h1>Your To-Do list</h1>
++<<<<<<< HEAD *1
+ <form method=”POST”>
+ <input id=”id_new_item” placeholder=”Enter a to-do item”/>
+ {% csrf_token %}
+ </form>
+ <table id = “id_list_table”>
+ <tr>
+ <td>
+ {{ new_item_text }}
+ </td>
+ </tr>
++======= *2
+ <input id=”id_new_item” placeholder=”Enter a to-do item” />
+ <table id=”id_list_table”>
++>>>>>>> chapter4-refactoring *3
</table>
</body>
</html>
ESCOD
*1 <<<<<<< HEAD
Changes are shown after the line <<<<<<< HEAD
.
*2 =======
, *3 >>>>>>> BRANCH-NAME
=======
divides your changes from the changes in the other branch, followed by >>>>>>> BRANCH-NAME
.
To see the beginning of the merge conflict in your file, search the file for the conflict marker
<<<<<<<
. When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line<<<<<<< HEAD
. Next, you'll see=======
, which divides your changes from the changes in the other branch, followed by>>>>>>> BRANCH-NAME
. In this example, one person wrote "open an issue" in the base or HEAD branch and another person wrote "ask your question in IRC" in the compare branch orbranch-a
.
If you have questions, please
<<<<<<< HEAD
open an issue
=======
ask your question in IRC.
>>>>>>> branch-a
Resolving a merge conflict using the command line
Secondly, edit the file that has merge conflicts.
Whichever you would prefer. If you delete <<<<<<< HEAD
, =======
and >>>>>>> BRANCH-NAME
are deleted automatically.
After I finished editing the file, I tried to merge.
$ git merge chapter4-refactoring
sources;
“Resolving a merge conflict using the command line”
In my case, When I commit the resolved file with git commit -m “tests.py passed” home.html, I get the error:
fatal: cannot do a partial commit during a merge.
After that, I type a following command;
git commit -i home.html
sources;
“Git error on commit after merge — fatal: cannot do a partial commit during a merge”
P.S. You’re tired of white and yellow, dull screen??
All you need to type a following command;
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
sources;
“A better git log”