Reputation: 43
I have 2 Git repositories with basically the same structure, but repository B has only some of the contents of repository A.
Repository A has newer commits that I need to push to B (but only the necessary files).
I have so far git clone'd the repositories to my local workstation. How should I replace the necessary files in repository B with files from repository A?
My naive attempt was git mv /A/source/* /B/source/
which resulted in:
fatal: /B/source/: '/B/source/' is outside repository
Since I'm fairly new to git, I'm not 100% sure what I should be trying to achieve. I'll try and explain the context: We have active development going on in repository A. Repository B is currently for a third party to access parts of the content (they only need parts of it). Repository A has version 1.6, B has 1.4. So my goal is to push the necessary new content to B. I guess this would be commiting the commits made to A during 1.5 and 1.6 to B?
Upvotes: 3
Views: 66
Reputation: 43
What we ended up doing was:
git rm /B/<files_to_replace>
cp /A/<necessary_files> /B/
git add ...
This might not be the correct way to do it, but we were in a bit of a hurry and it'll get the job done for now. Thanks for the help! :)
Upvotes: 0
Reputation: 16224
The most reliable way to do this, I think, is to transfer the actual commits themselves. Use git format-patch
to pull the commits from A
which are not on B
, or vice versa, and write them out to .patch
files.
Then, in the other repo, use git apply
to apply the .patch
file commits to that repo. If there are conflicts you will have an opportunity to resolve them.
This is basically the same as "cherry-picking" commits, but across repositories rather than across branches.
(You can also use git am
instead of git apply
if you want, it's only a bit different.)
Upvotes: 3