0

I had a git repository (call this repository A) for a project which is nearing public release. Over time, the repository has contained information which I would not like to make public (not passwords/SSH keys, but think similar). At one point in the past (when I thought we were nearing release), I created a new repository without the old history by running git clone --depth=1 (call this repository B). No development has occurred on repository A, but development continued on repository B. Now we are actually nearing release, and my boss would like to do this again, to create repository C.

I would like to join repositories A and B together to contain a single "legacy" repository containing the entire history from the beginning of the project to the first commit of repository C. The last commit of repository A and the first commit of repository B have the same hash. How can I create a new repository AB, which contains the entire history of the project, starting from the first commit of repository A to the last commit of repository B?

I have tried the following:

  • Adding repo B as a remote of repo A, then fetching and mergeing B/master into A/master; git just reports Already up-to-date., but HEAD and A/master remain at the last commit of repo A.
  • Adding repo A as a remote of repo B, then fetching and mergeing B/master into A/master, which git only allows if I use --allow-unrelated-histories. This just generates a giant merge conflict, with every file modified since the beginning of repo B listed as in conflict. I suppose if I could resolve all conflicts in favor of repo B, this would be an acceptable solution, but I'm not actually sure what the history tree would look like after this merge.

Is there any better way to do what I'm trying to accomplish?

caseygrun
  • 2,019
  • 1
  • 15
  • 21
  • Has the problem been solved so far? – Marina Liu Dec 15 '17 at 09:14
  • Possible duplicate of [How to merge two sequential git repositories](https://stackoverflow.com/questions/22945813/how-to-merge-two-sequential-git-repositories) –  Apr 10 '18 at 18:12

2 Answers2

0

To join repo A and repo B together with sequential history, you can use below commands:

git clone <URL for repo A>
cd A
git remote add B <URL for repo B> -f
git reset --hard B/master

In the local repo, local master branch contains all the sequential history. If you want to push the local repo to repo C, you can use below commands:

git remote set-url origin <URL for repo C>
git push -u origin master
Marina Liu
  • 36,876
  • 5
  • 61
  • 74
0

If the history is literally sequential, and repo B was made as a shallow clone of repo A (git clone --shallow <url of repo A>), all you have to do is un-shallow-ize repo B:

$ cd path/to/repo/B
$ git fetch --unshallow origin

to make B be a complete (no longer shallow) repository that contains all of the commits that are in A, plus any additional commits made to B.

On the other hand, you talk about adding repo A as a remote of repo B—but if you made repo B with git clone --shallow, A should already be a remote. So something is missing from your problem description.

torek
  • 448,244
  • 59
  • 642
  • 775