git - Detach subdirectory (that was renamed!) into a new repo -



git - Detach subdirectory (that was renamed!) into a new repo -

i have repository , detach 1 of directories new repo. this perfect place started, there 1 caveat, however: directory want detach renamed @ point. , if follow solution post new name of directory seems i'm loosing history before re-name. ideas of tweak create work in situation?

git filter-branch can operate on ranges of commits; can filter 'before' , 'after' separately, , utilize grafts tack them together:

git branch rename $commit_id_of_rename git branch pre-rename rename~ ## first filter commits rename, not rename git filter-branch --subdirectory-filter $oldname pre-rename ## add together graft, our rename rev comes after processed pre-rename revs echo `git rev-parse rename` `git rev-parse pre-rename` >> .git/info/grafts ## first filter-branch left refs backup directory. move away ## next filter-branch doesn't complain mv .git/refs/original .git/refs/original0 ## filter rest git filter-branch --subdirectory-filter $newname master ^pre-rename ## graft baked branch, don't need anymore rm .git/info/grafts

this marginally more complex if need filter multiple branches or tags; branches before rename can included first filter-branch, while ones after must included before ^rename in sec filter-branch.

another alternative add together index filter (or tree filter) instead checks both directories, old , new, , keeps whichever present.

since haven't provided test repository, here's quick sanity-check script scenario:

#!/bin/bash set -u set -e set -x rm -rf .git x y foo git init mkdir x echo initial > x/foo git add together x/foo git commit -m 'test commit 1' echo tc2 >> x/foo git commit -a -m 'test commit 2' mv x y git rm x/foo git add together y/foo git commit -a -m 'test rename' git branch rename head echo post rename >> y/foo git commit -a -m 'test post rename' git branch pre-rename rename~ git filter-branch --subdirectory-filter x pre-rename echo `git rev-parse rename` `git rev-parse pre-rename` >> .git/info/grafts mv .git/refs/original .git/refs/original0 git filter-branch --subdirectory-filter y master ^pre-rename rm .git/info/grafts git log -u

if procedure not work you, there else odd repository history haven't described, such rename hiding in history.

git git-filter-branch

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -