Git合并不同步回购 [英] Git Merge Out of Sync Repos

查看:105
本文介绍了Git合并不同步回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用git来跟踪我的自定义到第三方web应用程序。我与一直在使用git来跟踪他们的变化的顾问交流。我会尽量使这一点很容易理解。




  • 我有一个从我们的环境中导出的副本

  • 我使用导出作为基础[LOCAL]启动了一个存储库,并且定期对其进行提交

  • 顾问拥有自己的最新版本库(不包括我的更改)[3RDPARTY]

  • 我已经分叉他们的git仓库[远程]



现在,我想要做的就是通过并合并 [LOCAL] [REMOTE] 之间不同的所有文件。



我不关心我目前在本地的分行或历史记录。我只关心从现在起使用REMOTE和发送/接收拉请求与顾问进行交互。



您如何建议我可以这样做?我试图在LOCAL上创建一个新的分支,并用3RDPARTY中的更新文件覆盖所有文件。然后我希望这个新分支和我的常规开发分支之间的合并会给我一个冲突,所以我可以轻松地将它们与KDiff3合并,但它只是自动合并并覆盖所有我的更改。


<您尝试复制所有文件,只是得到一个合并,但它没有奏效。这应该有效,但我认为你可能需要遵循一些我将尝试解释的不同步骤。



应该有一个标签,或者检入 3RDPARTY ,这与您的导出环境中的签入点相同,这是首次签入 LOCAL 的签入点。我将调用这个签入 MERGE_BASE 。因此,请尝试以下步骤:


  • 首先, git checkout master on REMOTE ,并确保它是
    ,最新的是 3RDPARTY git pull origin

  • REMOTE git branch mergeb< MERGE_BASE> < MERGE_BASE> 是我在历史中谈到的
    checkin是相同的,或者接近
    等同于您将在您最初创建
    LOCAL 时使用。

  • 将您的最新版本的源复制到<$在
    <$ c $中创建的 mergeb 分支中的文件之上直接使用code> LOCAL C> REMOTE 。不要复制.git目录!

  • 在分支 mergeb 中使用 REMOTE git add 以确保所有的
    更改都应用于git索引,然后运行 git commit 。现在
    您的 REMOTE mergeb 分支应该与<$ c中的
    具有相同的源$ C> LOCAL 。 (你可以用你的本地
    更改来使用git remotes,但由于你不关心历史,我建议只需
    这样做就可以简化这个过程)。

  • 再次检出master分支 git checkout master

  • 此时创建一​​个新分支,您将使用它贡献给
    ..做 git checkout -b remote_work

  • 现在,简单地合并 mergeb 分支到你的 remote_work 分支
    git merge --no-ff mergeb 。在这一点上,你可能会
    与他们的工作有冲突的合并,你的工作要解决



    完成这个过程并将工作交给你的分支后,你现在应该处于你想要的状态。



    毕竟,如果你想要所有的工作在 remote_work 分支上显示 3RDPARTY 中当前显示的内容 REMOTE 简单地做 git rebase master



    REMOTE 上同步它们的 3RDPARTY 回购并保留尚未被拉入 remote_work REMOTE 回购协议中的其他各种分支中使用3RDPARTY



    让我知道这个过程是否适合您。

    I started using git to track my customizations to a 3rd party web app. I interface with consultants that have been using git to track their changes for a while. 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
    • The consultants have their own repository that is up to date (excludes my changes) [3RDPARTY]
    • I've forked their 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].

    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.

    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. 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.

    解决方案

    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. I will call this checkin 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.
    • 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.
    • 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. DONOT copy the .git directory!
    • 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. Now your REMOTE mergeb branch should have identical source to what is in 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).
    • Checkout the master branch again git checkout master.
    • At this point create a new branch that you will use to contribute to them.. do git checkout -b remote_work.
    • Now, simply merge the mergeb branch into your remote_work branch with 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.

    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.

    Let me know if this process works out for you.

    这篇关于Git合并不同步回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆