How can I add a specific folder when using git subtree?

后端 未结 2 752
执笔经年
执笔经年 2021-02-09 15:03

I have a complicated Ionic project I\'m developing. Many of the components and providers I\'m developing are generic and can be used in other projects my company is doing. This

2条回答
  •  旧时难觅i
    2021-02-09 15:53

    Before adding the subtree to my-app-repo, split a subtree from my-company-library-repo:

    # In my-company-library-repo
    git subtree split -P src/app/providers/... -b feature-new feature
    

    This will create a new history with the contents of src/app/providers/... at the root of the repo, starting at the feature branch, and create the branch feature-new at the end of this history.

    Then add that new branch as a subtree to my-app-repo:

    # In my-app-repo
    git subtree add -P  --squash  feature-new
    

    Now you will have the contents of src/app/providers/... at .

    You didn't mention whether you will be repeating this process regularly, but that is possible too. From the git-subtree man page:

    Repeated splits of exactly the same history are guaranteed to be identical (ie. to produce the same commit ids). Because of this, if you add new commits and then re-split, the new commits will be attached as commits on top of the history you generated last time, so 'git merge' and friends will work as expected.

提交回复
热议问题