简体   繁体   English

git-subtree pull 并发症

[英]git-subtree pull complications

We have been trying to get git-subtree working on a project (with git version 1.7.9.4) and have run into a bit of a complication.我们一直在尝试让git-subtree在一个项目上工作(使用 git 版本 1.7.9.4)并且遇到了一些复杂情况。 Someone else previous added the subtree with this command some months ago:几个月前,其他人之前使用此命令添加了子树:

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

Now there have been substantive changes to foo and we'd like to merge in those changes, ideally squashing them in. None of the files have been modified since they were imported.现在foo已经发生了实质性的变化,我们想合并这些变化,最好是将它们压扁。自导入以来,没有任何文件被修改。

I've tried three things to try and merge in the changes.我尝试了三件事来尝试合并更改。

First:第一的:

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

Which throws the exception: Can't squash-merge: 'foo' was never added.这引发了异常: Can't squash-merge: 'foo' was never added.

Second:第二:

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

This works (sort of), but has the issue of pulling in all of the commits and has conflicts with the files that have been modified.这有效(有点),但存在拉入所有提交的问题,并且与已修改的文件存在冲突。

Finally, I tried this:最后,我试过这个:

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

This gives me the desired result, with the output Automatic merge went well; stopped before committing as requested这给了我想要的结果,输出Automatic merge went well; stopped before committing as requested Automatic merge went well; stopped before committing as requested and all of the files showing up as modified (with the correct content). Automatic merge went well; stopped before committing as requested并且所有文件都显示为已修改(具有正确的内容)。

Ideally I'd like to continue using first git-subtree version and get an output close to the last version.理想情况下,我想继续使用第一个git-subtree版本并获得接近最后一个版本的输出。 If we have to use the last version consistently going forward, we will, but I am a little confused as to why the last one doesn't produce merge conflicts while the middle one does.如果我们必须始终如一地使用最后一个版本,我们会,但我有点困惑,为什么最后一个不会产生合并冲突,而中间的会产生合并冲突。

Any help is appreciated.任何帮助表示赞赏。

I had the same problem, and in my case it seems to be due to the initial subtree commit being merge-squashed into the master branch.我遇到了同样的问题,在我的情况下,这似乎是由于初始子树提交被合并压缩到主分支。

Looking through the subtree source I found this: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224查看子树源,我发现了这个: https : //github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224

It looks like subtree greps your git log for git-subtree-dir: foo but doesn't find a suitable commit.看起来子树会为git-subtree-dir: foo搜索您的 git 日志,但没有找到合适的提交。 Try git log --grep="git-subtree-dir: foo/*\\$" , and if there's something weird with that commit, such as it being a merge commit, that could be the issue.尝试git log --grep="git-subtree-dir: foo/*\\$" ,如果该提交有一些奇怪的东西,例如它是合并提交,那可能是问题所在。

Just pulling without squashing worked for me, apart from the annoying merge conflicts.除了烦人的合并冲突之外,只是拉而不挤压对我有用。 I did that in a temporary branch which I then git merge --squash ed into another branch to avoid a messier history.我在一个临时分支中这样做了,然后我git merge --squash ed 到另一个分支以避免更混乱的历史。 It could've been rebased instead too of course.当然,它也可以被重新定位。

I've been experiencing the same error Can't squash-merge: 'foo' was never added.我遇到了同样的错误Can't squash-merge: 'foo' was never added. with sourcetree 1.7.0 whenever I do a pull on a subtree.使用 sourcetree 1.7.0 每当我拉子树时。 However, I believe my case is different because I'm using subdirectories.但是,我相信我的情况有所不同,因为我使用的是子目录。

Sourcetree does something as follows: Sourcetree 执行以下操作:
git -c diff.mnemonicprefix=false -c core.quotepath=false subtree pull -P dir1\\subdir1 --squash remote-repo master

And obviously, if we were to try it again in Git Bash (Git version 2.6.1.windows.1), it would be:显然,如果我们在 Git Bash(Git 版本 2.6.1.windows.1)中再试一次,它会是:
git subtree pull -P "dir1\\subdir1" --squash remote-repo master

However that failed.然而那失败了。 The following also failed although the command syntax is fine:尽管命令语法很好,但以下也失败了:
git subtree pull -P dir1/subdir1 --squash remote-repo master

The solution I found to make it work is to use Git Bash with the following command:我发现使其工作的解决方案是通过以下命令使用 Git Bash:
git subtree pull -P "dir1/subdir" --squash remote-repo master

I guess that there is still some work to be done for Git's command-line processing engine.我想 Git 的命令行处理引擎还有一些工作要做。

This also happens, if the current clone is a partial clone (eg, when using --depth=1 ).如果当前克隆是部分克隆(例如,使用--depth=1 ),也会发生这种情况。 This is the default at GitHub Actions V2 .这是GitHub Actions V2的默认设置。

In the case of GitHub actions, this can be configured when using fetch-depth: 0 at the checkout step:对于 GitHub 操作,可以在结帐步骤使用fetch-depth: 0时进行配置:

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

This could happen when the main repository and the subtree repository has different set of commits.当主存储库和子树存储库具有不同的提交集时,可能会发生这种情况。

In my case I had updated the subtree from the local repository(using git subtree pull --squash -P foo local/foo.git master ) and the local repository changes were never pushed to origin.就我而言,我已经从本地存储库更新了子树(使用git subtree pull --squash -P foo local/foo.git master )并且本地存储库更改从未推送到源。

When I tried git pull --squash -s subtree git@example.com:foo.git master after this, I started getting the error.当我在此之后尝试git pull --squash -s subtree git@example.com:foo.git master ,我开始收到错误消息。

Just pushing the subtree repository solved the error.只需推送子树存储库即可解决错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM