* Merging two Git-Repositories
@ 2019-12-17 9:28 Steve Keller
2019-12-17 10:02 ` Roger Gammans
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Steve Keller @ 2019-12-17 9:28 UTC (permalink / raw)
To: git
Is it possible to merge one Git-Repository into another? I have
developed two independent repositories A and B, and now I find that
B should be part of A in new sub-directory, e.g. A/B. I want to
move B into A while keeping the whole development history of B.
How can I do that?
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Merging two Git-Repositories
2019-12-17 9:28 Merging two Git-Repositories Steve Keller
@ 2019-12-17 10:02 ` Roger Gammans
2019-12-17 11:03 ` Jared Tobin
2019-12-17 20:13 ` Stephan Beyer
2 siblings, 0 replies; 4+ messages in thread
From: Roger Gammans @ 2019-12-17 10:02 UTC (permalink / raw)
To: Steve Keller, git
On Tue, 2019-12-17 at 10:28 +0100, Steve Keller wrote:
> Is it possible to merge one Git-Repository into another? I have
> developed two independent repositories A and B, and now I find that
> B should be part of A in new sub-directory, e.g. A/B. I want to
> move B into A while keeping the whole development history of B.
>
> How can I do that?
It is possible bit isn't straightforward, at least not if you want to
interleave the commits.
If you don't want to interleave the commits, just rename everything (*)
in B to B/*' and merge the repo with A's repo. Then you will have a the
structure you want going forward, all the history together; but if you
check out a historic commit you will have to decide to check out on the
'A' or 'B' branches.
If you do want to interleave the comits the best found was (
https://metacpan.org/pod/distribution/Git-FastExport/script/git-stitch-repo
to merge the repos. (from https://github.com/book/Git-FastExport/ )
I've got some updates (
https://github.com/rgammans/Git-FastExport/tree/hintfiles ) to it when
I did some work on this a couple of years ago but the it looks like the
upstream has improved a little since then. My changes allow you to try
to give it hints in case in make mistakes, on choosing the correct
parent for a commit. The whole system worked pretty well except where
there were a lot a diverging/remerging branches.
My process was to write a shell script to actually drive the process,
and tweak the script to improve the results iteratively.
Hope this helps a little.
--
Roger Gammans <rgammans@gammascience.co.uk>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Merging two Git-Repositories
2019-12-17 9:28 Merging two Git-Repositories Steve Keller
2019-12-17 10:02 ` Roger Gammans
@ 2019-12-17 11:03 ` Jared Tobin
2019-12-17 20:13 ` Stephan Beyer
2 siblings, 0 replies; 4+ messages in thread
From: Jared Tobin @ 2019-12-17 11:03 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
On Tue, Dec 17, 2019 at 10:28:36AM +0100, Steve Keller wrote:
> Is it possible to merge one Git-Repository into another? I have
> developed two independent repositories A and B, and now I find that B
> should be part of A in new sub-directory, e.g. A/B. I want to move B
> into A while keeping the whole development history of B.
You can accomplish this with git-subtree(1), for which IMO the intuition
of "exotic merge commit" more or less suffices.
An example (from A):
git remote add B B_REMOTE_ADDRESS
git subtree add --prefix B B master
-- jared
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Merging two Git-Repositories
2019-12-17 9:28 Merging two Git-Repositories Steve Keller
2019-12-17 10:02 ` Roger Gammans
2019-12-17 11:03 ` Jared Tobin
@ 2019-12-17 20:13 ` Stephan Beyer
2 siblings, 0 replies; 4+ messages in thread
From: Stephan Beyer @ 2019-12-17 20:13 UTC (permalink / raw)
To: Steve Keller, git
On 12/17/19 10:28 AM, Steve Keller wrote:
> Is it possible to merge one Git-Repository into another? I have
> developed two independent repositories A and B, and now I find that
> B should be part of A in new sub-directory, e.g. A/B. I want to
> move B into A while keeping the whole development history of B.
If I get you right, you want a simple merge of two branches with no
common ancestors. Here's a line-by-line sh example with project A in
directory A and project B in directory B, and B will be merged into a
subdirectory "project-b" in A:
# change to B's directory
cd B
# create the subdirectory where B's files will be in A
mkdir project-b
# move all files into project-b
git mv -k * project-b
# probably check if this worked for you
ls
git status
# commit
git commit -m "Move all files into subdirectory for inclusion into A"
# change to A's directory
cd ../A
# fetch and merge B into A
git pull --no-rebase --allow-unrelated-histories ../B
# ... change commit message to something more meaningful ...
That's it.
If B is public you might want to replace its last commit by some commit
that adds a note that further development is going on in A.
Stephan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-17 20:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17 9:28 Merging two Git-Repositories Steve Keller
2019-12-17 10:02 ` Roger Gammans
2019-12-17 11:03 ` Jared Tobin
2019-12-17 20:13 ` Stephan Beyer
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).