git-subtree pull 并发症 [英] git-subtree pull complications

查看:30
本文介绍了git-subtree pull 并发症的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在尝试让 git-subtree 在一个项目上工作(使用 git 版本 1.7.9.4) 并遇到了一些复杂情况.几个月前,其他人使用此命令添加了子树:

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. Someone else previous added the subtree with this command some months ago:

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

现在对 foo 进行了实质性的更改,我们希望合并这些更改,最好将它们压缩.自导入以来,没有任何文件被修改.

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.

我尝试了三件事来尝试合并更改.

I've tried three things to try and merge in the changes.

首先:

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

这有效(有点),但存在拉入所有提交的问题,并且与已修改的文件存在冲突.

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.

最后,我尝试了这个:

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 and all of the files showing up as modified (with the correct content).

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

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.

感谢任何帮助.

推荐答案

我遇到了同样的问题,就我而言,这似乎是由于初始子树提交被合并压缩到主分支.

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.

查看子树源我发现了这个:https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224

Looking through the subtree source I found this: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224

看起来子树会为 git-subtree-dir: foo 搜索您的 git 日志,但没有找到合适的提交.尝试 git log --grep="git-subtree-dir: foo/*$",如果该提交有一些奇怪的东西,例如它是合并提交,那可能是问题所在.

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 merge --squashed 到另一个分支以避免更混乱的历史.当然,它也可以重新定位.

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 --squashed into another branch to avoid a messier history. It could've been rebased instead too of course.

这篇关于git-subtree pull 并发症的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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