git-subtree pull 并发症
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9777564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git-subtree pull complications
提问by David H. Clements
We have been trying to get git-subtreeworking on a project (with git version 1.7.9.4) and have run into a bit of a complication. Someone else previous added the subtree with this command some months ago:
我们一直在尝试让git-subtree在一个项目上工作(使用 git 版本 1.7.9.4)并且遇到了一些复杂情况。几个月前,其他人使用此命令添加了子树:
git subtree add --prefix=foo [email protected]: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 [email protected]: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 [email protected]: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 [email protected]:foo.git master
This gives me the desired result, with the output 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. 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.
理想情况下,我想继续使用第一个git-subtree
版本并获得接近最后一个版本的输出。如果我们必须一直使用最后一个版本,我们会,但我有点困惑,为什么最后一个不会产生合并冲突,而中间的会。
Any help is appreciated.
任何帮助表示赞赏。
采纳答案by Jacob Rask
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. 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 日志,git-subtree-dir: foo
但没有找到合适的提交。Try 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. It could've been rebased instead too of course.
除了烦人的合并冲突之外,只是拉而不挤压对我有用。我在一个临时分支中这样做了,然后我将其git merge --squash
编入另一个分支以避免更混乱的历史。当然,它也可以重新定位。
回答by Zaki Mohzani
I've been experiencing the same error Can't squash-merge: 'foo' was never added.
with sourcetree 1.7.0 whenever I do a pull on a subtree.
However, I believe my case is different because I'm using subdirectories.
Can't squash-merge: 'foo' was never added.
每当我拉子树时,我都会遇到与 sourcetree 1.7.0相同的错误。但是,我相信我的情况有所不同,因为我使用的是子目录。
Sourcetree does something as follows:git -c diff.mnemonicprefix=false -c core.quotepath=false subtree pull -P dir1\subdir1 --squash remote-repo master
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 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
However that failed. The following also failed although the command syntax is fine:git subtree pull -P dir1/subdir1 --squash remote-repo master
然而那失败了。尽管命令语法很好,但以下也失败了: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 subtree pull -P "dir1/subdir" --squash remote-repo master
我发现使其工作的解决方案是通过以下命令使用 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 的命令行处理引擎还有一些工作要做。
回答by koppor
This also happens, if the current clone is a partial clone (e.g., when using --depth=1
). This is the default at GitHub Actions V2.
如果当前克隆是部分克隆(例如,使用 时--depth=1
),也会发生这种情况。这是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
回答by Sarath VS
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 [email protected]:foo.git master
after this, I started getting the error.
当我git pull --squash -s subtree [email protected]:foo.git master
在此之后尝试时,我开始收到错误消息。
Just pushing the subtree repository solved the error.
只需推送子树存储库即可解决错误。