We have one big projectB and we want to use some part of it in different places in other project. For example,
git remote add -f Bproject /path/to/B
git merge -s ours --no-commit Bproject/master
git read-tree --prefix=dir-BA/ -u Bproject/master:subdirA
git read-tree --prefix=dir-BB/ -u Bprorect/master:subdirB
git commit -m "Merge B project as our subdirectory"
开发者_JS百科
It works well. Then we update subdirA and subdirB of projectB and try to use subtree merge strategy:
git pull -s subtree Bproject master
It does not what we expect from it. May be somebody knows how we can use different parts of projectB in other project?
It sounds like you might want to be using git-submodule
which allows you to pull the contents of another repo in as subdirectory of your repo's working copy. Here are some good resources for using git-submodule
:
- http://progit.org/book/ch6-6.html
- http://book.git-scm.com/5_submodules.html
- https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial
To be clear, the contents and histories of the repositories remains distinct but this sort of working copy stitching is generally what people want. Also note that submodule references point to particular versions (similar to svn externals
if you're familiar with them) which means they won't change without you intentionally updating them explicitly.
Let me know if I've misunderstood what you're trying to do.
精彩评论