简体   繁体   English

Git合并不同步存储库

[英]Git Merge Out of Sync Repos

I started using git to track my customizations to a 3rd party web app. 我开始使用git跟踪对第三方网络应用程序的自定义。 I interface with consultants that have been using git to track their changes for a while. 我与一直使用git跟踪其更改的顾问联系。 I'll try to make this easy to understand. 我将尽力使它易于理解。

  • I have a copy of an export from one of our environments 我有一个环境中的导出副本
  • I started a repository using the export as a base [LOCAL] and have been committing to it regularly 我以导出为基础[LOCAL]开始了一个存储库,并一直定期提交
  • The consultants have their own repository that is up to date (excludes my changes) [3RDPARTY] 顾问拥有自己的最新存储库(不包括我的更改)[3RDPARTY]
  • I've forked their git repo [REMOTE] 我已经分叉了他们的git repo [REMOTE]

Now from here all I want to do is go through and merge all the files that are different between [LOCAL] and [REMOTE] . 现在,我要做的就是浏览并合并[LOCAL][REMOTE]之间所有不同的文件。

I don't care about the branches or history I currently have in LOCAL. 我不在乎本地的分支机构或历史记录。 I only care about using REMOTE from now on and sending/receiving pull requests to interact with the consultants. 从现在开始,我只关心使用REMOTE以及发送/接收请求请求以与顾问进行交互。

How do you recommend I can do this? 您如何建议我可以做到这一点? I tried creating a new branch on LOCAL and overwriting all the files with the updated files from 3RDPARTY. 我尝试在LOCAL上创建一个新分支,并使用3RDPARTY中的更新文件覆盖所有文件。 Then I was hoping a merge between that new branch and my regular dev branch would give me a conflict so I could easily merge them all with KDiff3 but instead it just automerged and overwrote all my changes instead. 然后,我希望新分支与常规dev分支之间的合并会给我带来冲突,以便我可以轻松地将它们全部与KDiff3合并,但是它只是自动合并并覆盖了我的所有更改。

You tried to copy all the files over and just get a merge but it didn't work. 您试图将所有文件复制过来,只是合并了,但是没有用。 That should work, but I think you may need to follow some different steps which I'll try to explain. 那应该起作用,但是我认为您可能需要遵循一些不同的步骤,我将尝试解释这些步骤。

There should be a tag, or checking in 3RDPARTY that was identical to a checkin point in your export environment which is the first checkin to LOCAL . 应该有一个标签,或签入3RDPARTY ,它与导出环境中的签入点相同,这是LOCAL的第一个签入。 I will call this checkin MERGE_BASE . 我将其称为MERGE_BASE So try these steps: 因此,请尝试以下步骤:

  • First of all do git checkout master on REMOTE and make sure it is up to date with 3RDPARTY with git pull origin . 首先,在REMOTE上执行git checkout master ,并确保它与git pull origin 3RDPARTY是最新的。
  • In REMOTE git branch mergeb <MERGE_BASE> <MERGE_BASE> is the checkin I spoke about in the history that is identical, or as close as identical, to what you would have in your initial creation of LOCAL . REMOTE git branch mergeb <MERGE_BASE> <MERGE_BASE>是我在历史记录中谈到的签入,与您最初创建LOCAL <MERGE_BASE>相同或接近。
  • Copy the source for your most up to date version in LOCAL directly over top the files in your mergeb branch we just created in REMOTE . LOCAL最新版本的源代码直接复制到我们刚刚在REMOTE创建的mergeb分支中的文件mergeb DONOT copy the .git directory! 不要复制.git目录!
  • In REMOTE on branch mergeb use git add to make sure all your changes are applied to the git index and then run git commit . 在分支mergeb REMOTE上,使用git add确保所有更改都应用于git索引,然后运行git commit Now your REMOTE mergeb branch should have identical source to what is in LOCAL . 现在,您的REMOTE mergeb分支应该具有与LOCAL相同的源。 (you could use git remotes to do this with your LOCAL changes, but since you don't care about history I recommend just doing it this way to simplify the process). (您可以使用git remotes进行本地更改,但是由于您不关心历史记录,因此建议您以这种方式进行操作以简化过程)。
  • Checkout the master branch again git checkout master . 再次git checkout master分支git checkout master
  • At this point create a new branch that you will use to contribute to them.. do git checkout -b remote_work . 在这一点上,创建一个新分支,您将使用它们来做贡献。。执行git checkout -b remote_work
  • Now, simply merge the mergeb branch into your remote_work branch with git merge --no-ff mergeb . 现在,简单合并mergeb分支到您的remote_work分支git merge --no-ff mergeb At this point you will probably have all the conflicting merges with their work and your work to resolve. 在这一点上,您可能会将所有相互冲突的合并及其工作和您要解决的工作合并。

Once you finish this process and commit the work to your branch you should be now in the exact state you wanted. 完成此过程并将工作提交到分支机构后,您现在应该处于所需的确切状态。

After all of this, if you want all your work to appear as if you started with what is currently in 3RDPARTY while on the remote_work branch on REMOTE simply do git rebase master . 这一切后,如果您希望所有的工作出现,如果你开始与什么是目前在3RDPARTY而在remote_work分支REMOTE根本就git rebase master

From then on out I would keep master on REMOTE synced with their 3RDPARTY repo and keep your changes which hasn't been pulled into 3RDPARTY in the remote_work or other various branches on the REMOTE repo. 从那时起,我将使REMOTE master与他们的3RDPARTY库保持同步,并保留3RDPARTYremote_workREMOTE repo上的其他分支中提取到3RDPARTY中的remote_work

Let me know if this process works out for you. 让我知道这个过程是否适合您。

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

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