开发者

Splitting a Git repository based on arbitrary file paths

I have one git repository which I'd like to turn into two git repositories, however the split is not as simple as it seems git filter-branch --subdirectory-filter would like.

myRepo/
    a-main.js
    b-main.js
    a-other.js
    tests/
        a-tests.js
        b-tests.js

What I'd like to do is get another repository which only has the a-* files. Note that I've just named them this way for clarity, the actual files don't have a common pattern. There is only a few, so it's no problem to list them individually.

What I've tried:

git clone --no-hardlinks ~/myRepo ~/myRepoA
cd ~/myRepoA
git filter-branch --tree-filter "rm b-main.js tests/b-tests.js" \
                  --prune-empty HEAD

But this gives this output

Rewrite 4ce7... (1/46)rm: cannot remove `b-main.js': No such file or directory
rm: cannot remove `tests/b-tests.js': No such file or directory
tree filter failed: rm b-开发者_运维技巧main.js tests/b-tests.js

For bonus points:

Once this is done, how do I push it to a new repository on Github?


Turns out I was missing the -f flag:

$ git filter-branch --tree-filter "rm -f b-main.js tests/b-tests.js" \
                  --prune-empty HEAD

And for my own bonus points:

$ git remote rm origin
$ git remote add origin git@github.com:username/reponame.git
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜