Git: Subtree Merge into a Deeply Nested Subdirectory?

前端 未结 2 644
太阳男子
太阳男子 2021-02-07 04:33

I\'m attempting to use git\'s subtree merge stategy where the subdirectory into which I want to merge is nested fairly deeply - currently four levels deep.

I followed th

相关标签:
2条回答
  • 2021-02-07 05:11

    The subtree merge strategy artificially limits the depth of its search for where the subtree “fits” into the overall tree. Unfortunately this limit is hard coded (see match-trees.c:267).

    Luckily, Git 1.7.0 added the subtree=… option to the (default) recursive merge strategy. This option lets you exactly specify the prefix so that Git does not have to guess (as much).

    With Git 1.7.0 or later, try this:

    git pull -X subtree=sites/all/modules/my_module REMOTE_REPO master
    
    0 讨论(0)
  • 2021-02-07 05:12

    Clarifying for future readers, the solution is in the comments of Chris Johnsen's response. If you're seeing the "fatal: entry not found in tree" error, get rid of the trailing slash at the end of your subtree prefix.

    For example, if you are trying to pull a GitHub Pages subtree with a command like

    git subtree --prefix gh-pages/ pull origin gh-pages
    

    and there are conflicts you will get an error like

     * branch            gh-pages   -> FETCH_HEAD
    fatal: entry  not found in tree 6e69aa201cad3e5888f1d12af0d910f8a10a8ec3
    

    Just remove the trailing slash from the gh-pages directory

    git subtree --prefix gh-pages pull origin gh-pages
    

    This will work, and will try to merge. The worst scenario you can get is when the auto merge fails and you get an error like

    Automatic merge failed; fix conflicts and then commit the result.
    

    but you just have to resolve the conflicts manually and you are done.

    0 讨论(0)
提交回复
热议问题