git merge dev branch merged into master how to resolve conflicts
黄舟
黄舟 2017-05-02 09:23:41
0
6
1321

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"

Start merging dev to master and report an error

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 // on master

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

The entire contents of the file index.txt, under the master branch

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?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(6)
淡淡烟草味

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:

  1. 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;

  2. 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

过去多啦不再A梦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template