开发者

git surgery - splitting out a single repository into many repositories

开发者 https://www.devze.com 2023-02-03 16:24 出处:网络
I have an existing git repository: my-repo/ .git/ foo/ foo-content-开发者_开发知识库goes-here bar/

I have an existing git repository:

my-repo/
  .git/
  foo/
    foo-content-开发者_开发知识库goes-here
  bar/
    bar-content-goes-here

I wish to get the following repository structures:

my-foo-repo/
  .git/
  foo-content-goes-here

my-bar-repo/
  .git
  bar-content-goes-here

I've looked at Detach (move) subdirectory into separate Git repository. This almost does what I need.

I ran these commands:

$ cd path/to/my-repo/../
$ git clone --no-hardlinks my-repo foo-repo
$ cd foo-repo
$ git remote rm origin
$ git filter-branch --tag-name-filter cat --subdirectory-filter foo \
      --prune-empty -- --all
$ git reset --hard
$ git gc --aggressive
$ git prune

I say this almost works. Issues noted:

  1. The git gc --aggressive step takes over 2 hours for my repository. I have 13 repositories that need extracting from my current single repository. I can script this process, but would appreciate input into any ways to speed it up?
  2. git log and gitk show me the expected commits for the new foo-repo. gitX shows me the expected commits, plus a disconnected tree with the old history. The foo-repo directory size is much larger than I would expect, so presumably I have some stuff left over which needs cleaning up. I'm not sure how to get rid of this stuff? Do I even need to get rid of it prior to pushing?


You could try it the other way round: filter out your wanted directory in a working branch in your original workplace, and then push only that branch out to a new repository.

$ cd /path/to/global-repo

$ git branch work-foo master
$ git filter-branch --tag-name-filter cat --subdirectory-filter foo \
      --prune-empty work-foo

$ cd /path/to
$ mkdir foo-repo
$ cd foo-repo
$ git init
$ git pull /path/to/global-repo work-foo

You do not want to use the --all option to filter-branch if you walk this path.

0

精彩评论

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

关注公众号