git move directory to another repository while keeping the history -
first - apologies asking question. there lot of topics already. i'm not having luck them. lack of familiarity git not help.
i'm moving folder 1 git repo (which exists). e.g.
repo-1 ---- dir1 ---- dir2 ---- dir3 ---- dir-to-move ---- dir5 repo-2 ---- dir1 ---- dir2 ---- dir3
in end want repos like
repo-1 ---- dir1 ---- dir2 ---- dir3 ---- dir-to-move ---- dir5 repo-2 ---- dir1 ---- dir2 ---- dir3 ---- dir-to-move
i.e. time dir-to-move exist in both repos. i'll migrate latest changes repo-2 , remove dir-to-move repo-1.
my initial research made me believe needed use filter-branch. e.g.
how move files 1 git repo preserving history using `git format-patch`and `git am`
i've since learnt subtree superseded approach. it's not doing expected. thought i'd able like
in repo-1 workspace
git subtree split -p dir-to-move -b split
to filter split branch down dir-to-move , it's history. in repo-2 workspace
git remote add repo-1 repo-1-url.git git subtree add --prefix dir-to-move split
this move code across. also, sort of, includes history
e.g.
cd repo-2 git log
shows commits repo-1
but
cd repo-2 git log dir-to-move
shows 'add dir-to-move commit ....'
i.e. history included not show when checked specific files/directories.
how can properly?
i can't git subtree
, filter-branch
it's possible.
first need create common repository contain both source , destination branches. can done adding new "remote" beside "origin" , fetching new remote.
use filter-branch
on source branch rm -rf
directories except dir-to-move
. after you'll have commit history can cleanly rebased or merged destination branch. think easiest way cherry-pick
non-empty commits source branch. list of these commits can obtained running git rev-list --reverse source-branch -- dir-to-move
of course, if history of dir-to-move
non-linear (already contains merge commits), won't preserved cherry-pick, git merge
can used instead.
example create common repo:
cd repo-2 git remote add source ../repo-1 git fetch source
example filter branch
cd repo-2 git checkout -b source-master source/master cmd="rm -rf dir1 dir2 dir3 dir5" git filter-branch --tree-filter "$cmd"
example cherry-pick destination master
cd repo-2 git checkout master git cherry-pick `git rev-list --reverse source-master -- dir-to-move`
Comments
Post a Comment