Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

Consider the following scenario:

I have developed a small experimental project A in its own Git repo. It has now matured, and I'd like A to be part of larger project B, which has its own big repository. I'd now like to add A as a subdirectory of B.

How do I merge A into B, without losing history on any side?

1 Answer

0 votes
by (12.4k points)

The branch of another repository can be placed under a subdirectory with their history. Like: 

git subtree add --prefix=rails git://github.com/rails/rails.git master

Here this will appear as a single commit, however, the commit's title contains a reference to the old history tree:

 Add 'rails/' from commit <rev>

Where <rev> is a SHA-1 commit hash. You can still see the history, blame some of the changes

git log <rev>

git blame <rev> -- README.md

 And then it's like a usual file move commit, need a jump when reaching it.

# finishes with all files added at once commit

git log rails/README.md

# then continue from original tree

git log <rev> -- README.md 

For more information on Git, you can join git training.

Browse Categories

...