git-subtree拉动并发症

时间:2012-03-19 20:37:45

标签: git merge git-subtree

我们一直试图让git-subtree处理一个项目(使用git版本1.7.9.4)并且遇到了一些复杂问题。几个月前,其他人之前使用此命令添加了子树:

git subtree add --prefix=foo git@example.com:foo.git master

现在foo已经发生了实质性的变化,我们希望合并这些变化,最好将它们压缩。自导入文件以来,没有任何文件被修改过。

我已尝试过三件事来尝试合并这些变化。

首先:

git subtree pull --squash -P foo git@example.com:foo.git master

抛出异常:Can't squash-merge: 'foo' was never added.

第二

git subtree pull -P foo git@example.com:foo.git master

这可以(有点),但是有拉入所有提交的问题,并且与已修改的文件有冲突。

最后,我尝试了这个:

git pull --squash -s subtree git@example.com:foo.git  master

这为我提供了所需的结果,输出Automatic merge went well; stopped before committing as requested和所有文件显示为已修改(包含正确的内容)。

理想情况下,我想继续使用第一个git-subtree版本并获得接近上一版本的输出。如果我们必须一直使用最后一个版本,我们会,但我有点困惑为什么最后一个版本不会产生合并冲突,而中间版本。

感谢任何帮助。

4 个答案:

答案 0 :(得分:9)

我有同样的问题,在我的情况下,它似乎是由于初始子树提交被合并压缩到主分支。

通过子树源我找到了这个:https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224

看起来像子树grep你的git-subtree-dir: foo的git日志,但找不到合适的提交。尝试git log --grep="git-subtree-dir: foo/*\$",如果有一些奇怪的提交,例如它是合并提交,那可能就是问题。

除了烦人的合并冲突之外,只是在没有挤压的情况下拉动我。我在一个临时分支中做到了这一点,然后我git merge --squash进入另一个分支,以避免更糟糕的历史。当然,它也可能已被改造。

答案 1 :(得分:2)

每当我对子树进行拉动时,我一直遇到与sourcetree 1.7.0相同的错误Can't squash-merge: 'foo' was never added.。 但是,我相信我的情况不同,因为我正在使用子目录。

Sourcetree做了以下事情:
git -c diff.mnemonicprefix=false -c core.quotepath=false subtree pull -P dir1\subdir1 --squash remote-repo master

显然,如果我们再次在Git Bash(Git版本2.6.1.windows.1)中再试一次,那将是:
git subtree pull -P "dir1\subdir1" --squash remote-repo master

然而失败了。虽然命令语法很好,但以下也失败了:
git subtree pull -P dir1/subdir1 --squash remote-repo master

我发现使其工作的解决方案是使用Git Bash和以下命令:
git subtree pull -P "dir1/subdir" --squash remote-repo master

我想Git的命令行处理引擎还有一些工作要做。

答案 2 :(得分:0)

如果当前克隆是部分克隆(例如,使用--depth=1时),也会发生这种情况。这是GitHub Actions V2的默认设置。

对于GitHub操作,可以在结帐步骤中使用fetch-depth: 0进行配置:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v2
        with:
          ref: master
          fetch-depth: 0

答案 3 :(得分:0)

当主存储库和子树存储库具有不同的提交集时,可能会发生这种情况。

就我而言,我已经使用git subtree pull --squash -P foo local/foo.git master从本地存储库更新了子树,并且本地存储库的更改从未被推送到源。

此后尝试git pull --squash -s subtree git@example.com:foo.git master时,我开始收到错误消息。

只需推动子树存储库即可解决该错误。

相关问题