we have repository, in couple of directories have been extracted submodules 2 years ago.
as git submodules cause headaches, decided revert extraction submodules , bring directories parent repository.
now question is, what best way - while keeping history.
i thinking of adding submodules remote , cherry-picking changes. need tell git shouldn't treat paths of commit relative current directory, not parent repo's root.
does 1 no way cherry-pick or other clever way?
thanks lot!
you can git filter-branch, using example in man page or modified version in answer. man-page version in git v1.8.2:
to move whole tree subdirectory, or remove there: git filter-branch --index-filter \ 'git ls-files -s | sed "s-\t\"*-&newsubdir/-" | git_index_file=$git_index_file.new \ git update-index --index-info && mv "$git_index_file.new" "$git_index_file"' head first, add each submodule remote in parent repo, checkout master branch of each local tracking branch (e.g. submodulea-master, submoduleb-master, etc.). git throw warning because branches don't share history, otherwise let proceed. rewrite submodule branch's history appropriate subdirectory , merge parent's master. in end, you'll have series of merge commits subdirectories, , cohesive, singular history in parent repo.
it sounds far more complex is. sure make backups in case goes wrong. script whole thing can try until right. rough order of execution every submodule is:
git remote add submodule submodule_remote git checkout -b submodule-master submodule/master git filter-branch ... # index-filter described above. # depending on length of history, # take quite while process/ git checkout master # on parent's master. now you're faced choice. rewrite parent remove traces of submodules, or not? if latter, remove submodule parent repository using solution appropriate git version, , git merge submodule-master. if want erase submodule commits history, too, can rewrite parent git filter-branch.
i once did 35 disparate repositories. here's tip: spend $10 on few hours of cluster-compute in aws. git filter-branch extremely ram bound. laptop couldn't in 20 hours aws cluster-compute instance finish on lunch. it's beautifully simple, cheap way conduct operations this.
one final note. if use bsd sed there's fair chance \t substitution in man page fail. jeff king's perl version work around issue:
git filter-branch --index-filter ' git ls-files -s | perl -pe "s{\t\"?}{$&newsubdir/}" | git_index_file=$git_index_file.new git update-index --index-info && mv $git_index_file.new $git_index_file ' head
Comments
Post a Comment