git merge remote branch (with conflict)

Source: Internet
Author: User
Tags commit manual git mergetool

Application Scenarios

Two people in the team fetch a branch at the same time. The first person changes after the submission, the second person submits the failure. The failure information is as follows:

Error:failed to push some refs to ' git@git.oschina.net:jacarrichan/jacarrichan.git '
hint:updates were rejected Beca Use the remote contains work, which you do
Hint:not has locally. This was usually caused by another repository pushing hint:to the
same ref. Want to first integrate the remote changes
hint: (e.g., ' git pull ... ') before pushing again.
Hint:see the ' Note about Fast-forwards ' "Git push--help ' for details.

Although the use of "Git push-f" can also be submitted, but will be the first person on the remote to wash off, too violent, not very good. The following is a manual merge.


Solutions

1, get the remote branch update, that is, the first person submitted:

Git fetch origin


2, try the automatic merge brought by git:

git merge origin/master     # #将origin/master Merge to current branch
If the contents of the two branches are different, the merge fails.

Auto-merging readme.md
CONFLICT (content): Merge CONFLICT in readme.md
Automatic merge failed; fix conflicts and T Hen commit the result.



Look at the current status and look for help information:

Jacarri@jacarri-pc/f/temp/mvn/jacarrichan (master| Merging)
$ git Status
# on branch Master
# you have unmerged paths.
#   (fix conflicts and run "git Commit")
#
# unmerged paths:
#   (use "git add <file> ..." to mark Resolution)
#
#       both modified:      readme.md
#
No changes added to commit (use "git add" and/ or "Git commit-a")



Now let's take a look at the contents of the "readme.md" file in the working directory:

Jacarri@jacarri-pc/f/temp/mvn/jacarrichanc (master| Merging)
$ cat readme.md
#jacarrichan only for




ochina git test.


<<<<<<< HEAD
This is the second person to
submit ............. =======
This is the first person to submit the
>>>>>>> origin/master


![ My blog] (http://service.t.sina.com.cn/widget/qmd/1597668397/99810a10/1.png ""
)

"<<<<<<< HEAD" Below is the current version of the content, and "=======" under, ">>>>>>>origin/master" The corresponding conflicting tolerance in the test branch is indicated above. What we do when we fix a conflict is to remove the "<<<<<<< HEAD", "=======" and ">>>>>>> test" stuff First, Then change the code to what we want.


Need to install configuration beyondcompare, download address

Configuration. Gitconfig:c:\users\${user.home}\.gitconfig

[diff]   
    Tool = BC3
[difftool "BC3"]   
    cmd = \ "D:/application/beyondcompare/bcompare.exe\" \ "$LOCAL \" \ "$REMOTE \"  
    Trustexitcode = True	
[Difftool]   
    prompt = False   
[merge]
    tool = Bc4   
[mergetool "Bc4"]   
    cmd = \ "d:/ Application/beyondcompare/bcompare.exe\ "\" $LOCAL \ "\" $REMOTE \ "\" $BASE \ "\" $MERGED \ "   
    Trustexitcode = True


Manual merge

Jacarri@jacarri-pc/f/temp/mvn/jacarrichanc (master| Merging)
$ git mergetool  readme.md
Merging:
readme.md

Normal merge conflict for ' Readme.md ' :
  {Local}: Modified file
  {remote}: Modified file hit
return to start Merge Resolution tool (BC4):

Note: This corresponds to "\" $LOCAL \ "\" $REMOTE \ "\" $BASE \ "\" $MERGED \ "in the three dark blue circled and in the configuration file above the picture.



In accordance with the above rules, I choose to add both sides of the content, you accept the first or other content can be written. Re-submit after saving is smooth.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.