Git:子树合并到一个深度嵌套的子目录中? [英] Git: Subtree Merge into a Deeply Nested Subdirectory?

查看:60
本文介绍了Git:子树合并到一个深度嵌套的子目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用git的子树合并策略,其中要合并到的子目录嵌套得很深-目前有四个层次.

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.

我遵循了此处将模块存储库添加为远程存储库,运行git read-tree将远程代码获取到本地存储库的子目录中,然后提交这些更改.

I followed the directions here to add the module repository as a remote, run git read-tree to get the remote code into a subdirectory in my local repo, and commit those changes.

当我尝试将更改从远程拉入并合并到主项目的master分支中时,我的问题就出现了.上一页的第5步建议使用-s子树开关进行git pull.当我的子目录深为一,二或三级,而不是四级时,这对我来说是正确的.

My problem comes when I try to pull and merge changes from the remote into the master branch of my main project. Step 5 at the page above suggests a git pull with the -s subtree switch. This works correctly for me when my subdirectory is one, two or three levels deep, but not four.

这里是合并到2级深的子目录中的结果.您可以看到站点/全部/中的自述文件已正确更新.在我的远程仓库中,自述文件位于根目录中.

Here is the result of the merge into a subdirectory 2 levels deep. You can see that the README file in sites/all/ has been updated correctly. In my remote repo, the README is in the root.

$ git pull -s subtree REMOTE_REPO master
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /path/to/my/REMOTE_REPO
 * branch            master     -> FETCH_HEAD
Merge made by subtree.
 sites/all/README |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

此处子目录深3级:sites/all/modules/.进行更改并更新文件也可以正常工作.

Here the subdirectory is 3 levels deep: sites/all/modules/. This works fine, too, pulling the changes and updating the files.

$ git pull -s subtree REMOTE_REPO master
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /path/to/my/REMOTE_REPO
 * branch            master     -> FETCH_HEAD
Merge made by subtree.
 sites/all/modules/README |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

但是现在我的代码位于4级深的子目录中:sites/all/modules/my_module/.Git似乎从REMOTE_REPO中提取了更改,但是它没有更新文件,而是告诉我它已经是最新的了.

But now my code is in a subdirectory 4 levels deep: sites/all/modules/my_module/. Git seems to pull the changes from REMOTE_REPO, but it doesn't update the files, instead telling me that it's already up to date.

$ git pull -s subtree REMOTE_REPO master
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /path/to/my/REMOTE_REPO
 * branch            master     -> FETCH_HEAD
Already up-to-date!
Merge made by subtree.

如果我立即再次运行它,它不会拉出更改或更新文件.

And if I run it again right away, it doesn't pull the changes or update the files.

$ git pull -s subtree REMOTE_REPO master
From /path/to/my/REMOTE_REPO
 * branch            master     -> FETCH_HEAD
Already up-to-date.

此时查看git日志将向我显示来自远程仓库和合并的更改,但我的结帐中的文件尚未更新.

Viewing the git log at this point will show me the changes from the remote repo and the merge, but the files in my checkout have not been updated.

这是一个错误,还是我做错了什么?

Is this a bug, or am I doing something wrong?

更新:克里斯·约翰森(Chris Johnsen)提供了以下选项,这会引发错误:

Update: Chris Johnsen offered the following option, which throws an error:

$ git pull -X subtree=sites/all/modules/my_module/ REMOTE_REPO master
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /Users/jeff/work/checkouts/compass_suite
 * branch            master     -> FETCH_HEAD
fatal: entry  not found in tree 173d4f16af4d2d61ae5c4b3446c392e8b49cc57d

推荐答案

subtree 合并策略人为地限制了其搜索子树适合"于整个树的位置的深度.不幸的是,这个限制是硬编码的(请参阅

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).

幸运的是,Git 1.7.0在(默认)递归合并策略中添加了 subtree =…选项.此选项使您可以精确地指定前缀,以使Git不必猜测(太多).

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).

在Git 1.7.0或更高版本中,请尝试以下操作:

With Git 1.7.0 or later, try this:

git pull -X subtree=sites/all/modules/my_module REMOTE_REPO master

这篇关于Git:子树合并到一个深度嵌套的子目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆