2

I want to combine 2 git repositories, and I want to preserve file history but I do not want to preserve commit history. In other words, I want to keep the changes over time, but I don't care about the SHA checksums. I will not need the old repositories after the merge.

The answers to the following questions do not help me, because I always end up with a repo with two roots and separate commit history:

What I want to do, is the exact opposite of Detach (move) subdirectory into separate Git repository, where git subtree is used to filter out all the commits that affect the files in a subdirectory.

My two repositories have some overlapping directory structure, but no overlapping files (except for .gitignore and .gitattributes) and I want to merge them at the root of a repository.

Both repositories have tags that have a slightly different naming scheme, but point to a specific release. For example repoA has tags A-1.0.0, A-1.0.1 and repoB has tags B-1.0.0, B-1.0.1. I don't really care about the commits between the tags, different branches or one branch, but at the tags there must be a merge point somehow.

The only idea I can come up with so far that may work (I have tried everything I could find with subtrees and merges):

  1. add repoB as a remote
  2. add a branch in repoA (mergeB) at a point in history before tag A-1.0.0
  3. cherry-pick the commits from repoB up to tag B-1.0.0 onto the branch mergeB
  4. checkout A-1.0.0
  5. merge branch mergeB
  6. cherry-pick every commit from repoA from old tag A-1.0.0+1 up to the old HEAD
  7. branch again
  8. repeat steps 3-7 for the next tags
  9. when everything is done, do a rebase (maybe interactive) to clean up stuff

This sounds like a lot of manual work, is there a better way to do this?

Community
  • 1
  • 1
Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101

1 Answers1

-1

Try the following steps. You are basically copying the files from one to the other, and then starting with a fresh repo. Alternatively, init in a third location and copy both old ones to it.

git clone repo1 a
git clone repo2 b
cp -r a b
rm -rf a/.git
rm -rf b
cd a
git init

BTW, there are tools for converting snv to Git that will preserve history, so maybe you should investigate using them.

Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40
  • I think I was not clear. I want to preserve file history, but I do not want to preserve the commit hashes. The conversion from svn to git went quite well, which is implied by the fact that my git repos have tags. In fact, that they came from svn is not relevant and confusing so I will edit that out. – Amedee Van Gasse Jun 18 '15 at 20:43