git branch study notes 2- resolve merge conflicts

Source: https: //www.liuhaolin.com/git/115.html

git merge conflicts in different branches with different contents of a file which, if it will merge conflict. Files may be added file, such as in the two branches are built the same file, but they have different content, or in both branches have updated the same file, but with different update. Eventually leading to different content in the same file in different branches. If you need to merge, you must manually resolve the conflict or revocation of the merger.

 

"Creating a conflicting merge"

git example of resolving conflict

          git example of resolving conflict

Initializing a warehouse, and then create a  devbranch, add a branch in the file  master-dev.txt, and then submitted to the  devbranch. Switch to the  masterbranch, the same operation is also presented with a document master-dev.txt, equally committed to the master branch, but the contents of the two documents are different. If you want to  devbranch to submit master, the code will be a conflict.

Create a "conflict"

echo " test - to submit the code conflict " > the README 
git the init. 
git the Add. 
git the commit -m ' the init ' 
# Create a dev branch, and switch to the dev branch 
git Checkout - b dev 

# current branch dev 
git Branch 
# * dev 
# Master 
echo " dev " > the MASTER dev.txt 

# dev branch filed in 
Git the commit -m ' [dev branch] dev.txt the Add-Master File ' 


Git Checkout Master 
echo " Master " > the MASTER  dev.txt
Git the Add.
git commit -m '[master branch ]add file master-dev.txt'

The dev branches merged master code and see what the situation.

# Dev branch of the code into the current branch, which is the master branch in 
git Merge dev 

# automatically merged file master - dev.txt 
Auto -merging The MASTER dev.txt 

# prompt a conflict, merge conflicts in master - dev. TXT 
cONFLICT (the Add / the Add): merge conflict in The MASTER dev.txt 

# automatic merge failed to modify a conflict, then submit the results of 
automatic merge failed; fix conflicts and then commit the result.

  There is a conflict, this is the time  master-dev.txt the content is modified, the contents of the file will have two branches  converge  master-dev.txt file.

cat master-dev.txt
<<<<<<< HEAD
master
=======
dev
>>>>>>> dev

  Caveats that had a conflict, and the current file  master-dev.txtis modified. This time, only to resolve the conflict. Then the next step. For example, you want to look at  dev分支the file  master-dev.txt whether the content has been modified, and this time could not see, because the first resolution of the conflict. In fact, when conflicts arise, it can not be switched branches. This has the advantage is that there is a problem is to prevent contamination of other code branches.

Checkout dev git 
Master-dev.txt: Needs Merge 
# conflict must be resolved before the current index area of 
error: you need to resolve your current index first

Resolve conflicts in the merge codes

  git using  7 + Left arrow current branch , and equals 7 7 + current branch right arrow  to indicate the code of conflict, a total of three lines. After resolving conflict is to modify the code and delete these three lines. For example, this modification is to delete these three lines.

  

cat master-dev.txt
master
dev

  After modifying the current state look

Status git 
the On Branch Master 
# there is no part of the success of the merger 
by You have have unmerged Paths. 
# fix bugs, and submit to mention 
  (and a Conflicts FIX RUN "git the commit") 
# use git merge --about termination of the merger 
  (use "git merge - ABORT "to ABORT at the merge) 

# no merged file 
Unmerged Paths: 
  (use" git the Add <file> ... "to Mark Resolution) 
        both-added: Master-dev.txt

  Modify the file conflict, the conflict has not been resolved  , because the file did not commit. We did not continue to merge, merger or revoked. I still can not switch branches.

git checkout dev
master-dev.txt: needs merge
error: you need to resolve your current index first

  Here submit it and see the results.

Master dev.txt the Add-Git 
Git the commit -m 'both the commit' 

# current branch is Master 
CAT dev.txt Master- 
Master 
dev 

# dev branch switch to 
CAT-Master dev.txt 
dev 
# dev can see the contents of the branch exchange is the original content, has not changed.

  This will merge the conflicting branch, there is a problem that  dev branch content and  master content branch is different. How can sync?

# In the dev branch, updates the master 
git rebase master 

#First, REWINDING Replay your head to Top of Work ON IT ... 
# Fast-Forwarded dev to master. 

# This show, and now content dev branch and master branch the content is the same. 
Master-dev.txt CAT 
Master 
dev

  

 

Guess you like

Origin www.cnblogs.com/flzs/p/11302559.html