Why write this article, because some time ago there was an open source GitHub project, a friend submitted a PR, looked at the next is to help optimize the code (thank you very much for this netizen). However, the PR submitted by him happens to have many conflicts with my project, which makes it impossible to merge automatically. In GitHub, you can only use command line instructions to merge, because this situation is rarely handled. For the convenience of future use, please record here.
About command merge instruction in GitHub
1. First, we need to download a git distributed management tool
Download git link address: https://git-scm.com/
2. Then we need to clone our project
git clone [email protected] :YSGStudyHards/NPOI-ExportWordAndExcel- ImportExcelData.git (SSH project link)
3. Create and switch to the branch, and synchronize to the master
Git checkout - B creates the branch name master
Use git branch to view the current branch
4. Pull the conflicting PR to the branch
git pull https// github.com/ Someone's / project's.git master
Command statements in GitHub
git pull git://github.com/hongbobaoer/NPOI-ExportWordAndExcel-ImportExcelData.git 20201109
5. Open the conflict file directly and resolve the conflict manually
When the project is pulled down, we need to resolve the conflicting file information
From the conflict content in the conflict file below, we know that:
<<<<<<< HEAD On June 19, pingrixuexilianxi added content ======= On June 18, pingrixuexilianxi2 modified this file >>>>>>> a8284fd41903c54212d1105a6feb6c57292e07b5
< head to = = = = = = = = [content added to pingrixuexilianxi on June 19] is the content submitted by the commit just now = = = = = = = = = = = to > > > > > > > in a8284fd41903c54212d1105a6feb6c57292e07b5, [file modified by pingrixuexilianxi2 on June 18] is the content updated by the remote code base (that is, the modified content pushed by the local code base of pingrixuexilianxi2). The manual conflict resolution method is to delete unnecessary code according to the project requirements. If it is needed, we only need to delete all the codes in the < head = = = = = = = > > > > > > > a8284fd41903c54212d1105a6feb6c57292e07b5 to solve the conflict (note that these symbols can’t exist in the end of the project, otherwise the exception may be reported). Or you can use git visual management tool (recommended)
Reason: because some people are unfamiliar with code merging, in order to avoid mistakes, it is recommended to use sourcetree for conflict resolution merging.
Detailed use of sourcetree address reference: https://www.cnblogs.com/Can-daydayup/p/13128633.html
6. Merge changes and update on GitHub
Note: you need to use your own code to perform merge, submit and update operations only when you don’t use visual tools to merge!
Git commit - A // submit the modification to the new branch, and you will be prompted to merge the local code into the person's code base Git checkout master // switch to its own main branch Name of the branch created by git merge // merge the new branch into its own branch Git push origin master // push the code to the remote repository
Here is the article about using git to handle conflicting pull requests in GitHub. For more information about GitHub handling conflicting pull requests, please search previous articles of developer or continue to browse the following articles. I hope you can support developer more in the future!