Generation and resolution of conflicts in git under multi-person development

Source: Internet
Author: User
Tags commit git mergetool
the emergence of conflictMany commands can conflict, but fundamentally, merge and patch (apply patches) conflict. And rebase is the process of re-setting the benchmark and then applying the patch, so it will also conflict. Git pull automatically merge,repo sync automatically rebase, so git pull and repo sync also clash. Git rebase, of course, not to mention it. Types of conflicts Logical Conflictsgit automatically handles (merges/applies patches) successfully, but logically there is a problem. For example, another person modified the file name, but I also use the old file name, in this case the automatic processing can be successful, but in fact there is a problem. For example, the function return value changes, but I also use the old meaning, this situation is automatically processed successfully, but may hide a major bug. This problem is mainly ensured by automated testing. Therefore, it is best to be able to write more complete automated test cases. The solution to this conflict is to make a bug fix. is not a real solution to the GIT report conflict. Content ConflictsTwo users modify the same area of the same file, and git reports content conflicts. We are all familiar with this, and the latter solution is mainly for this kind of conflict. Tree ClashA conflict caused by a file name modification is called a tree conflict. For example, a user renaming a file to a a.c,b user renaming the same file to B.C will cause a conflict when B merges the two commits. $ git status
Added by US:B.C
Both deleted:origin-name.c
Added by THEM:A.C if finalized with B.C, then the solution is as follows: Git RMA.c
Git RMOrigin-name.c
git add B.C
Git commit executes the previous two git RM, will alarm "file-name:needs merge", can ignore. Tree conflicts can also be solved with git mergetool, but the whole process is done in interactive questions and answers, using D to delete unwanted files and C to keep the required files. Finally execute git commit commit. solutions to content conflicts Discover ConflictsIn general, there will be "CONFLICT" when there is a conflict:
$ git pull
Auto-merging Test. txt
CONFLICT (content): Merge CONFLICT inch Test. txt
Automatic merge failed; Fix conflicts and ThenCommit the result.   However, there are exceptions, Repo sync error, may not directly prompt the conflict, but the following: Error:project mini/sample Note: Regardless of whether there is a conflict, as long as the local modification is not based on the latest server, it can report this error, the workaround is the same. This time, you need to go to the error item (Git library) directory, and then execute git rebase solution: Git rebase remote-branch-name the general process of conflict resolution conflict resolution in Merge/patchEdit the conflict first, and then Git commit commits. Note: For git, there is no difference between edit conflicts and normal code changes. After the modification is complete, the changes are added to the cache and then commit. conflict resolution in RebaseThe rebase conflict resolution process is the process of resolving each application patch conflict.   After resolving a patch application conflict, execute the following command to mark the conflict resolved (that is, add the changes to the cache): Git add-u Note:-u means that all new changes to the track file are added to the cache, but not the new file. Then execute the following command to continue Rebase:git rebase-- ContinueHave conflicts continue to resolve, repeat these steps until rebase is complete. If you encounter a patch in the middle does not need to be applied, you can use the following command to ignore: Git rebase--skip If you want to go back to the state before rebase execution, you can do: git rebase--abort Note: rebase, no commit is required, there is no The new changes need to be committed, which is done automatically by Git. ways to edit conflicts edit conflicting files directlyAfter the conflict has been created, the contents of the file system's conflicting files (here is Test.txt) will appear similar to the following: A123
<< << << < HEAD
b789
== == == =
b45678910
>> >> >> > 6853E5FF961E684D3A6C02D4D06183B5FF330DCC
C Where: conflict markers <<<<<<< (7 <) and ======= are my modifications, and the content between ======= and >>>>>>> is someone else's modification.   At this point, no other junk files have been generated. The simplest way to edit a conflict is to directly edit the conflicting file (test.txt), delete the conflict marker, and resolve the conflict correctly. resolve conflicts with graphical interface toolsIf there are many conflicts to resolve, and more complex, the graphical interface of the conflict resolution tool is very important. Execute git mergetool To resolve conflicts with pre-configured beyond Compare:
$ git Mergetool
Merging:
Test. txt

Normal merge Conflict for' Test.txt ':
{Local}: Modified
{Remote}: modified the above three windows are "LOCAL", "BASE", "remote" in order, they simply provide the information needed to resolve the conflict and cannot be edited.   The following window is the result of the merge, can be manually modified, or you can click the corresponding color arrow to select "LOCAL" or "REMOTE". After you modify the conflict save in beyond compare, the conflicting tags in the conflict file (Test.txt) are gone, and the conflicting edits of a file are completed. Note:After you start beyond compare, several auxiliary files with uppercase names and numbers are automatically generated: when you close beyond compare, these auxiliary files are automatically deleted. At the same time, a Test.txt.orig file is generated that resolves the conflict scene before the conflict. By default, the. orig file may not be deleted automatically and needs to be deleted manually. Originating From: http://www.cnblogs.com/sinojelly/archive/2011/08/07/2130172.html

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.