I have two repos. First repo (let's call it A) started a while ago; second repo (B) started very recently. Now we're thinking we would rather have just made B a subdirectory of A. So I'd like to do that, but keep B's commit history.
- I want the full commit history. i.e. I don't want to just squash B's history into one patch and drop that as a new commit in A.
- I do not care to preserve the exact SHA1s of B (I understand that that's probably impossible).
- I do not care to preserve the timestamps of B's commits (though that would be nice to have).
- I do not care to preserve authorship.
- I just want to preserve the diffs/patches of each of B's commits.
- I don't care to preserve any notion of two separate repositories. In fact, I want there only to be A going forward.
- I don't need B to be a git submodule of A, with its own
.git
dir or anything like that.
At the end of whatever operations are done, I want three criteria satisfied:
- The files and directories as seen at the
HEAD
of B are seen in a subdirectory of A i.e./path/to/repoB/somefile.js
is found at/path/to/repoA/B/somefile.js
- All the commit messages of B are seen, in order, at the chronological end of the commits of A
- The diffs of each commit are available (viewable by
git log
, etc.)
Some examples may clarify what I intend:
- In repo B, commit 1 is to add
file.txt
- commit 2 is to edit
file.txt
- So in repo A, I want two new commits:
- repo A commit 98: add
B/file.txt
- repo A commit 99: edit
B/file.txt
EDIT:
Merge git repository in subdirectory has been proposed as a duplicate of my question. I'll admit that it is extremely close to what I'm asking, and has several fine answers. I tried the subtree
answer there, as well as the rebase --onto
answer. Both were very close, but were unsatisfactory: subtree
didn't allow git log
to see the history across the repository histories without referring to path/to/file/without/repo-subdir
(where I moved B into repo-subdir
); and rebase --onto
didn't make B's history visible from A's HEAD
.