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.