Conflict resolution in Git

Source: Internet
Author: User

Conflicts can occur in many commands, but fundamentally, merge and patch (applying 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. Conflicting type logic conflicts git automatically handles (merges/applies patches) successfully, but logically problematic. 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 conflicts two users have modified 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. A conflict caused by a tree conflict 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. Resolution of content conflicts found conflict in 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 may 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-The general procedure for the name conflict resolution is to merge/patch the conflict before editing the conflict, 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. Rebase Conflict resolution 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, adding the content 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 is added. 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 apply, you can use the following command to ignore: Git rebase--Skip if you want to go back to the rebase state before execution: Git rebase--Abort Note: After rebase, no commit is required, and no new modifications are required to commit, which is done automatically by Git. Edit conflicting methods directly edit the conflicting file conflicts, the contents of the conflicting files in the file system (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. The use of graphical interface tools to resolve conflicts if you want to resolve a lot of conflicts, 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. Zz:http://www.cnblogs.com/sinojelly/archive/2011/08/07/2130172.html

Conflict resolution in Git

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.