简体   繁体   English

将远程git repo与本地git repo合并

[英]merging remote git repo with local git repo

I have a Php project in Laravel framework. 我在Laravel框架中有一个Php项目。

Initial CODE STATE : A 初始代码状态:A

One month later , another developer joins me. 一个月后,另一位开发商加入了我的行列。

After 6 months , 6个月后,

My CODE STATE : A + B 我的密码状态:A + B

His CODE STATE : A + C 他的代码状态:A + C

B and C have many common files so we are expecting conflicts during git merge. B和C有许多公共文件,因此我们期望git merge期间发生冲突。 We now wish to have a code base : A + B + C 现在,我们希望有一个代码库:A + B + C

My current status/strategy-in-progress : I have set up a remote git repository with code A + C and local git repository with A + B . 我当前的状态/进行中的策略:我已经用代码A + C建立了一个远程git仓库,并使用A + B建立了一个本地git仓库。

how to best merge remote git repository(A+B) with my local git repository(A + C) so that i have A+B+C on the both local and remote git repo? 如何最好地将远程git存储库(A + B)与我的本地git存储库(A + C)合并,以便我在本地和远程git存储库上都具有A + B + C?

Please assist! 请协助!

Let's assume that A + C is in master, and A + B is in a pull request branch. 假设A + C在master中,而A + B在pull request分支中。 If B and C modified the same files, they may cause merge conflicts with each other, so you want to resolve these before merging your pull request branch into master to make it easier to review and integrate. 如果B和C修改了相同的文件,它们可能会导致彼此合并冲突,因此,您需要在将pull request分支合并到master中之前解决这些冲突,以使其更易于查看和集成。 As a result, you should either merge master into your pull request branch (which will add a merge commit with parents B and C) or rebase your pull request branch against master (which will change your branch's commits to A + C + B ). 因此,您应该将master合并到您的pull request分支中(这将添加与父B和C的合并提交),或者将您的pull request分支基于master进行基础(这会将您的分支的提交更改为A + C + B )。

I suggest you to make two branches from A , for example: MY_A and HIS_A then you can add B and C to your branches: MY_A + B and HIS_A + C solve conflict, then try to add the rest of the work to both and choise the easiest to solve like this: 我建议您从A创建两个分支,例如: MY_AHIS_A然后可以将BC添加到分支中: MY_A + BHIS_A + C解决冲突,然后尝试将其余工作添加到这两个分支中并选择这样最容易解决:

MY_A + B + C or HIS_A + C + B MY_A + B + CHIS_A + C + B

but using branches you never lost your work and always you can do this localy for not alter the repository 但是使用分支,您永远不会丢失工作,并且始终可以在不更改存储库的情况下进行此本地设置

Update: 更新:

first pull you master branch ( A+C ): 首先拉您的master分支( A+C ):

$ git pull origin master

then create a branch from master branch an create AC : 然后从master分支创建一个分支,然后创建一个AC

$ git checkout -b AC master

before change to the other branch ensure to have all your work commited 在更改到另一个分支之前,请确保已完成所有工作

then create another branch from master branch an create AB : 然后从master分支创建另一个分支,并创建一个AB

$ git checkout -b AB master

here you are in other branch, you can add his code and commit it without worry about to delete or change files 在这里,您在其他分支中,可以添加他的代码并提交,而不必担心删除或更改文件

see your branches use: 查看您的分支机构使用:

$ git branch

change to a branche AC use: 更改为分支AC使用:

$ git checkout AC

change to branche AB use: 更改为分行AB使用:

$ git checkout AB

Now you have two branches that you can see the diff read this , and use git diff AC..AB to see the diference in the terminal, and what will happend if you do a merge between two branches. 现在,您有两个分支,您可以看到diff 阅读this ,并使用git diff AC..AB查看终端中的差异,以及如果在两个分支之间进行合并会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM