Marc Borni
Marc Borni

Reputation: 514

Git individual file history lost with git subtree

I'm merging 2 git repositores (old1 & old2) into 1 (new1). My requirements are to merge all branches & to keep the git commit history. First one I can achieve but I'm struggling with the commit history.

This is the command I execute to merge the old1 repo in a sub folder of the new1: git subtree add -P old1 https://github.com/example/old1.git master

Output of git log --graph --oneline --decorate --all:

*   ad4fcb6 (HEAD -> master, origin/master, origin/HEAD) Add 'komed-connector/' from commit '50b42475113c295c66c4050b3b0f119a6ebff62b'
|\  
| * 50b4247 Updated komed-shared
| *   1a5435a Merge branch 'master' into openshift_build
| |\  
| | *   8aa90aa Merge branch 'r/3.4'
| | |\  
| | | * a6cea77 updated shared
| | * | a40c782 Updated komed-shared
...

So far so good: git commit history is kept. But if I'm inspecting the git commits of a single file in the new sub folder it doesn't show all commits: enter image description here

How can I merge 2 repos into 1 and keep the individual file git commit history? So when running gitk old1/Dockerfile git shows me all commits that happened on the old repository.

Upvotes: 4

Views: 1255

Answers (1)

sbat
sbat

Reputation: 1898

My understanding is that Git does not have the concept of "individual file commit history". Tracking of the fact that old1/Dockerfile is related to some other file in some different location is left to heuristics in visual and command line tools (or lack thereof). More discussion of this can be found in this question: git, sure-fire way to move/rename files while keeping the history

From the practical standpoint, I would try rewriting the "old" repo history as if it entirely occured in the oldreporoot/old1 folder. Then this repo can be merged cleanly into the new repo, and your visual/command line tools should behave accordingly, as files are not renamed/moved.

git filter-branch --tree-filter should help get this done, as described in https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

Upvotes: 4

Related Questions