问题
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 masteronREMOTEand make sure it is up to date with3RDPARTYwithgit pull origin. - In
REMOTEgit 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 ofLOCAL. - Copy the source for your most up to date version in
LOCALdirectly over top the files in yourmergebbranch we just created inREMOTE. DONOT copy the .git directory! - In
REMOTEon branchmergebusegit addto make sure all your changes are applied to the git index and then rungit commit. Now yourREMOTEmergebbranch should have identical source to what is inLOCAL. (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
mergebbranch into yourremote_workbranch withgit 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