编程知识 cdmana.com

Using git to handle the conflicting pull requests submitted in GitHub

Preface :

   Why write this article , Because some time ago, there was an open source github A friend of mine submitted a pr Look at the next is to help optimize the next code ( Thank you very much ). But he submitted pr It happens that there are many conflicts with my project, which makes it impossible to merge automatically , stay github You can only merge using command line instructions , Because this situation is less handled, for the convenience of future use, here to record .

github The general command merge instruction in

1、 First we need to download a git Distributed management tools

download Git Link address :https://git-scm.com/

2、 And then we need to clone Next, our project

git clone sgit@github.com:YSGStudyHards/NPOI-ExportWordAndExcel-ImportExcelData.git(ssh Project links )

3、 Create and switch to the branch , And sync to master in

git checkout -b  Created branch name  master

Use git branch View the current branch

 4、 Pull the conflicting pr Into the branch

git pull https//github.com/ Someone's / Of a project .git master  

github The command sentence in

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 conflicting file information   

From the conflict content in the following conflict file, we understand that :
<<<<<<< HEAD
6 month 19 Japan  pingrixuexilianxi Added content 
=======
6 month 18 Japan  pingrixuexilianxi2 I modified this file 
>>>>>>> a8284fd41903c54212d1105a6feb6c57292e07b5
<<<<<<< HEAD To ======= Inside 【6 month 19 Japan pingrixuexilianxi Added content 】 It's just my own Commit Submitted content
======= To >>>>>>> a8284fd41903c54212d1105a6feb6c57292e07b5 Inside 【6 month 18 Japan pingrixuexilianxi2 I modified this file 】 It's the content of the remote code base update ( That is to say pingrixuexilianxi2 Local code base push changes ).

Manual conflict resolution

Delete unnecessary code according to the project requirements , If we need both, we just need to put  <<<<<<< HEAD=======     >>>>>>> a8284fd41903c54212d1105a6feb6c57292e07b5 Delete the conflict and it's solved ( Be careful , At the end of the project, none of these symbols exist , Otherwise, an exception may be reported ).

Or you can use git Visual management tools ( recommend )

reason : Because some people are unfamiliar with code merging , In order to avoid mistakes, it is recommended to use sourcetree To resolve conflicts and merge .

Detailed use sourcetree Address reference :https://www.cnblogs.com/Can-daydayup/p/13128633.html

6、 Merge changes and place in GitHub Update on

Be careful : This is when you do not use visualization tools to merge, you need to use your own code to perform the merge , Submit , update operation !

git commit -a // Commit the changes to the new branch , Will prompt you to succeed merge Local code to this person's code base 

git checkout master // Switch to your main branch 

git merge  Created branch name  // Merge new branches into your own branches 

git push origin master // Push the code to a remote repository 

 

版权声明
本文为[Time chaser]所创,转载请带上原文链接,感谢

Scroll to Top