git-subtree conflict when pulling from central repo

后端 未结 4 946
天涯浪人
天涯浪人 2021-01-17 10:21

I have several projects that depend on the same library, for which I\'d like to maintain a separate git repository to be managed with git-subtree within each project. So for

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-17 10:51

    Inside your main project, try to pull and push with squash commands always :

    step 1 : subtree pull with a squash

     git subtree pull --prefix=mainProjectFolder/subtreeFolder http://bitbucket.org/repo.git master --squash
    

    step 2 : subtree push with a squash

     git subtree push --prefix=mainProjectFolder/subtreeFolder http://bitbucket.org/repo.git master --squash
    

    squash flag will avoid creation of new SHA1 id's for the same commit in different repositories.

    Explanation : To over come this issue you can make it a convention to use the squash flag while pushing and pulling your subtree. The issue described by @Borg about SHA1 commit id's is correct, but subtree were not really built for this. You should avoid to keep the commit Id' of the subtree(library) repository in both the parent project and subtree project. And if at all you push changes from the parent repository to the subtree repository follow this statement from the documentation(line 58): That is, if you make a change that affects both the library and the main application, commit it in two pieces.

    Also this video explains it when not to use subtrees. Drag straight to 11:00 minutes to find that subtree's are not the correct solution for you if :

    you have constant updates to the repository,

    or, if you have many dependencies,

    or, if everyone in the team has to learn subtrees.

提交回复
热议问题