Git conflicts occur with multi-user collaboration, and in some cases git can automatically merge intelligently, but sometimes users need to merge manually.
(This article links: http://blog.csdn.net/u012150179/article/details/14047183) one. Git Smart Auto Merge
1. Multi-member modification of different files this is in accordance with the "non-fast-forward push" described earlier, and is resolved (http://blog.csdn.net/u012150179/article/details/36044515) in its own way.
2. Multiple members modify different regions of the same file 3. Simultaneously modify the file name and the contents of the Files
Workaround: All three of the above methods can be resolved in the same way, that is, the pull operation before the push is performed, i.e.
Git pull
Over here
Git pull = git fetch + git merge Refs/remotes/origin/master
two. User Merge manually
1. File Merging (Modify the same region of the same file)Now simulate the occurrence of this situation. (Note: I am here to build a git server first, the method is visible http://blog.csdn.net/u012150179/article/details/ 17029731) There are two users User1 and User2 created from the share repository clone content. and modify the second line of the file Conflict_test file at the same time, after User1 executes the push, the user2 execution push will take the following scenario:
Figure 1
In the log message, you are prompted to use Git pull, and then try git pull to see the result:
Figure 2
The information obtained is: "Automatic merge failed, need to repair conflict before commit." "That is, in the case of the above" Git Smart Auto-merge "situation, now git can not perform automatic merging, at this time the user needs to manually merge to solve the problem.
To view repository status:
Figure 3
Problem Solving methods:The best way to do this is to use Mergetool to enter
Git mergetool
Get
Figure 4, carriage return
The KDIFF3 graphical interface appears, where area A is modified, area B is modified locally (local), Area C is remote repository, and at the bottom right click to select the repository you want to use, and then save to exit.
This completes the manual merge of the conflict.
After:
Git commit–m ""
Git push Origin Master
Can. To view the commit log:
Figure 5
You can see that the latest commit is a merge of the first two commits.
2. Tree merge (different members rename the same file)About tree collisions, the reason for this is because a file is renamed at the same time. You can also use Mergetool to fix conflicts, but the more straightforward way is to use git rm to delete the files you want to delete, add the required files to staging area and commit using git Add.
There is also a useful command in file merging and tree merging:
Git ls-files–s
To view the staging area file.
other articles of reference:
Http://yodalee.blogspot.com/2013/03/vimdiffgit-merge-conflict_28.html
Http://www.cnblogs.com/sinojelly/archive/2011/08/07/2130172.html