Using git branch to merge into the master mainline, but because one file was modified at the same time, there were many more files after the merge <<<HEAD
Like this! How to resolve conflicts? Do I have to manually edit the conflict file and remove those <<<HEAD
>>>DEV
before submitting?
cd ~
mkdir demo
cd demo
git init
git status // on branch master
echo "first line " >> index.txt
git add . && git commit -m "first head"
git status // on branch master
git branch // * master
git branch dev
git checkout dev
git branch // * dev ,master
ls // index.txt
echo "sec line in dev" >> index.txt
git add . && git commit -m "in branch dev"
git checkout master
git status // on branch master
echo "sec line on branch master" >> index.txt
git add . && git commit -m "2"
git merge dev
Auto-merging index.txt
CONFLICT (content): Merge conflict in index.txt
Automatic merge failed; fix conflicts and then commit the result.
git diff index.txt
diff --cc index.txt
index dda3583,8fa96cd..0000000
--- a/index.txt
+++ b/index.txt
@@@ -1,2 -1,2 +1,6 @@@
first line
++<<<<<<< HEAD
+sec line on branch master
++=======
+ sec line in dev
++>>>>>>> dev
first line
<<<<<<< HEAD
sec line on branch master
=======
sec line in dev
>>>>>>> dev
Merge dev to master, and this file appears <<< HEAD
>>> dev
Like this, how to merge them successfully? Do I have to edit it manually and submit it again?
If there is any conflict, you must edit it manually! This problem usually occurs in multi-person teams! When resolving conflicts, try to work with your teammates!
If a conflict occurs during merge when it is determined that it can be merged (for example, when there is no problem with the branch code), manual processing is necessary. Of course, handling conflicts on the master is a pain in the ass. So another method is needed.
There are two ideas:
Use master to merge the dev branch, so that the conflict occurs under the dev branch. After manually resolving it, merging it back to master is just a fast-forward;
Use git rebase
Yes, because you have changed the same place, you need to manually resolve the conflict. Just merge the marked locations into one code. Or you can use cherry-pick or rebase to prevent certain conflicts
Generally, the master branch is used to merge the dev branch. The actual conflict resolved is on dev. It is recommended to carefully look at the conflict differences to avoid affecting other people's code.
Although command line tools are very powerful, it is still very convenient to use visual tools after understanding the principles, especially when resolving conflicts.
When such a conflict occurs, it must be carefully resolved manually. Using visualization tools, you can easily view conflicts and quickly jump between conflict points. Most conflicts can be resolved with just a few clicks of the mouse.
It is recommended to use git with the command line and visual tools. A better visual tool is TortoiseGit
It is recommended to use visual diff tools such as p4merge. In addition, as long as developers use git in compliance with the specifications, there will be no merge master conflicts. It is recommended to strengthen training for developers and standardize the use of git. Currently, I use git-flow here.