Git Merge Out of Sync Repos

别说谁变了你拦得住时间么 提交于 2019-12-12 02:29:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8823654/git-merge-out-of-sync-repos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!