Two days ago, a git historical map was sent to the group, as follows:
According to the submission history, we can see that all branch merges in the figure adopt merge mode. For specific operation of merge, please read the following article.
According to the requirements of the project, if git submission history is required to be a relatively simple timeline, rebase merging can be used; if there is no such requirement, merge can be used, and its branch tree is network structure, but each submission is relatively clear. For their differences, please refer to the differences and examples of GIT merge and git rebase
- Rebase merge: the essence is to cancel your own submission, save it temporarily, update the current branch to the latest origin branch, and finally apply your own commit.
- Merge merge: merge and commit the two branches.
(1) The code of remote fetch is not modified locally, but can be rebased directly;
(2) If the file is modified locally and there is no add or rebase, the prompt “cannot rebase: you have unstated” will be displayed changes.Please Commit or stash them. “If there is no commit after add, you will be prompted with” cannot rebase: your index contains uncommitted ” changes.Please commit or stash them.”。 After commit, if the same file is not modified, rebase will not conflict.
(3) If the same file is modified locally, there are two situations: after commit and when rebase, there are two situations:
① If the same location is not modified, it can be rebase without conflict;
② If the same location is modified, there will be a conflict when rebase. At this time, GIT has been merged, but its own submission is not applied. Solution: modify the conflicting file, and then execute add and rebase — continue operations. If you are not careful, the commit is executed after the add is executed. At this time, the head of the local warehouse is in the free state. How to solve this problem and supplement it later.
Merge merge may also have conflicts. Resolving conflicts is similar to rebase. After processing conflict files, you can submit them again.
Suppose you have three people (GIT1, git2, git3) working together to develop a project.
(1) GIT1 create project, add index.html File, add “create by GIT1” to the index file and submit it;
After git2 pulls the file, add “add by git2” to the index and submit it;
After git3 pulls the file, add “add by git3” to the index and submit it;
After GIT1 pulls the latest code, add “add by GIT1 ADD1 by GIT1” in the index, as follows:
Submit the remote warehouse, and the branch tree is as follows:
(2) Git2 adds “add 1 by git2” to the index file to test the conflict
The branch tree is as follows:
Then the execution of rebase conflicts:
The branch tree is (at this time the branch is (no branch, rebuilding DEV)):
Open the conflict file. The conflict part is identified by < < < < < < < < = = = = = = = = = = = = = = = = = = = = = = > > > > > > > > > > > to process the code of this part. The processed file is as follows:
Execute add and rebase — continue
Rebase ends, and the branch tree is:
After remote submission, the final branch tree is as follows:
(3) The index file of git3 is as follows:
Modify the first line of “create by” in “modify” modified by “place”.
Pull the latest file from the remote and execute rebase
The final results are as follows:
(4) GIT1 creates an index2.html file, which is pushed after submission and rejected remotely because the local version is not the latest version and needs to be submitted after updating to pull the latest file.
GIT1 performs the merge operation, and the final branch tree is as follows:
Summarize and modify different parts of the same file, merge and merge will not conflict. Modify the same place of the same file, merge will conflict. Solution: rebase, resolve the conflict, execute add + rebase continue; merge, resolve the conflict, and submit again
This article introduces the implementation of GIT branch merge conflict resolution method. For more related git branch merge conflict resolution content, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!