如何管理与 git 子模块的冲突?
我有一个引用多个子模块的 git 超级项目,我试图锁定一个工作流程,以便我的项目成员的其余部分在其中工作。
对于这个问题,假设我的超级项目名为 supery
,子模块名为 subby
。 (然后是我想做的事情的简化......我实际上并没有使用版本分支,但我认为将其作为一个问题来布局是最简单的。)
我的 supery 的主分支 具有 git 项目 subby
的标签 v1.0
作为子模块引用。 supery
的分支调用了 one.one
并将子模块的引用更改为指向 subby< 的标签
v1.1
/代码>。
我可以在每个分支中顺利工作,但是如果我尝试使用 master
分支的更改来更新 one.one
分支,我会收到一些冲突,但我不这样做不知道如何解决它们。
基本上在运行 git pull 后。 master 而在 subby
分支中,看起来它创建了额外的子模块。
在拉取/合并之前,我从 one.one
分支的 git submodule
获得了所需的响应:
$ git checkout master
$ git submodule
qw3rty...321e subby (v1.0)
$ git checkout one.one
$ git submodule
asdfgh...456d subby (v1.1)
但是在拉取之后,当我运行 时,它会添加其他子模块git submodule
:
$ git pull . master
Auto-merged schema
CONFLICT (submodule): Merge conflict in subby - needs qu3rty...321e
Automatic merge failed; fix conflicts and then commit the results.
$ git submodule
qw3rty...321e subby (v1.0)
asdfgh...456d subby (v1.1)
zxcvbn...7890 subby (v1.1~1)
如何删除/忽略不需要的子模块引用并提交我的冲突和更改? 或者是否有一个参数可以与我原来的 git pull 一起使用,该参数会忽略我的子模块?
I have a git superproject that references several submodules and I am trying to lock down a workflow for the rest of the my project members to work within.
For this question, lets say my superproject is called supery
and the submodule is called subby
. (Then is a simplification of what I'm trying to do...I'm not actually using the branches for versions, but I thought it would be easiest to lay out as a question.)
My master branch of supery
has the tag v1.0
of the git project subby
referenced as a submodule. The branch of supery
called one.one
and changed the reference of the submodule to point to the tag v1.1
of subby
.
I can work within each of these branches without a hitch, but if I try to update the one.one
branch with changes from the master
branch I receive some conflicts and I don't how to resolve them.
Basically after running a git pull . master
while in the subby
branch, it looks like it creates additional submodules.
Before the pull/merge, I get the desired response from git submodule
from the one.one
branch:
$ git checkout master
$ git submodule
qw3rty...321e subby (v1.0)
$ git checkout one.one
$ git submodule
asdfgh...456d subby (v1.1)
But after the pull, it adds additional submodules when I run git submodule
:
$ git pull . master
Auto-merged schema
CONFLICT (submodule): Merge conflict in subby - needs qu3rty...321e
Automatic merge failed; fix conflicts and then commit the results.
$ git submodule
qw3rty...321e subby (v1.0)
asdfgh...456d subby (v1.1)
zxcvbn...7890 subby (v1.1~1)
How do I delete/ignore the unwanted submodule references and commit my conflicts and changes? Or is there a parameter I can use with my original git pull
that will ignore my submodules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
好吧,它在技术上并不能管理与子模块的冲突(即:保留这个而不是那个),但我找到了一种继续工作的方法......我所要做的就是注意我的 git 状态 输出并重置子模块:
这会将子模块重置为预拉提交。 在这种情况下这正是我想要的。 在其他情况下,我需要将更改应用于子模块,我将使用标准子模块工作流程(签出主模块、下拉所需标签等)来处理这些更改。
Well, its not technically managing conflicts with submodules (ie: keep this but not that), but I found a way to continue working...and all I had to do was pay attention to my
git status
output and reset the submodules:That would reset the submodule to the pre-pull commit. Which in this case is exactly what I wanted. And in other cases where I need the changes applied to the submodule, I'll handle those with the standard submodule workflows (checkout master, pull down the desired tag, etc).
我对这个问题的答案有点挣扎,并且对 类似的 SO 帖子 也可以。 所以这对我有用 - 请记住,在我的情况下,子模块是由不同的团队维护的,因此冲突来自主模块和我正在处理的项目的本地分支中的不同子模块版本:
git status
- 记下有冲突的子模块文件夹将子模块重置为当前分支中最后提交的版本:
git reset HEAD path/to/submodule
此时,您已经有了子模块的无冲突版本,您现在可以将其更新到子模块存储库中的最新版本:
现在您可以
提交
并返回工作。I struggled a bit with the answers on this question and didn't have much luck with the answers in a similar SO post either. So this is what worked for me - bearing in mind that in my case, the submodule was maintained by a different team, so the conflict came from different submodule versions in master and my local branch of the project I was working on:
git status
- make a note of the submodule folder with conflictsReset the submodule to the version that was last committed in the current branch:
git reset HEAD path/to/submodule
At this point, you have a conflict-free version of your submodule which you can now update to the latest version in the submodule's repository:
And now you can
commit
that and get back to work.我在使用 git rebase -i origin/master 到分支时遇到了这个问题。 我想采用子模块引用的主版本,所以我简单地执行了:
git reset master path/to/submodule
然后
git rebase --continue
这解决了问题我。
I had this problem with
git rebase -i origin/master
to a branch. I wanted to take master's version of the submodule ref, so I simply did:git reset master path/to/submodule
and then
git rebase --continue
That solved the problem for me.
我以前没有见过那个确切的错误。 但我对你遇到的麻烦有一个猜测。 看起来是因为
supery
的master
和one.one
分支包含subby
子模块的不同引用,当您合并来自master
的更改,git 不知道v1.0
或v1.1
应该由保留和跟踪哪个参考
分支。supery
的 >one.one如果是这种情况,那么您需要选择所需的引用并提交更改以解决冲突。 这正是您使用 reset 命令所做的事情。
这是跟踪项目不同分支中子模块的不同版本的一个棘手方面。 但是子模块引用就像项目的任何其他组件一样。 如果两个不同的分支在连续合并后继续跟踪相同的相应子模块引用,那么 git 应该能够计算出该模式,而不会在将来的合并中引发合并冲突。 另一方面,如果频繁切换子模块引用,您可能不得不忍受大量冲突解决。
I have not seen that exact error before. But I have a guess about the trouble you are encountering. It looks like because the
master
andone.one
branches ofsupery
contain different refs for thesubby
submodule, when you merge changes frommaster
git does not know which ref -v1.0
orv1.1
- should be kept and tracked by theone.one
branch ofsupery
.If that is the case, then you need to select the ref that you want and commit that change to resolve the conflict. Which is exactly what you are doing with the reset command.
This is a tricky aspect of tracking different versions of a submodule in different branches of your project. But the submodule ref is just like any other component of your project. If the two different branches continue to track the same respective submodule refs after successive merges, then git should be able to work out the pattern without raising merge conflicts in future merges. On the other hand you if switch submodule refs frequently you may have to put up with a lot of conflict resolving.
首先,找到您想要子模块引用的哈希值。 然后运行
它,这对我有用,使我的子模块获得正确的哈希引用,并继续我的工作,而不会出现任何进一步的冲突。
First, find the hash you want to your submodule to reference. then run
that has worked for me to get my submodule to the correct hash reference and continue on with my work without getting any further conflicts.
从这次讨论中得到了帮助。
就我而言,这
对我有用:)
Got help from this discussion.
In my case the
worked for me :)
以上所有内容对我都不起作用......
我将子模块放在“未合并路径”下,然后我被卡住了......
最终经过多次尝试后,有效的是:
从子模块中手动删除合并冲突文件而不是在主存储库中:
(这将其移至“未暂存提交的更改:”)
然后
All the above didn't work for me...
I had the submodule under "unmerged path" and I was stuck...
Eventually after many many attempts what worked was:
deleting manually the merge conflicts file from the sub-module than in main repo:
(this moved it to "Changes not staged for commit:")
then
好吧,在我的父目录中,我看到:
所以我只是这样做了
Well In my parent directory I see:
So I just did this
如何解决与 git 子模块的冲突,在包含它们的外部存储库中
选项 1:
像 主要答案:
然后,完成后通过冲突解决,手动
cd
进入每个子模块,拉取或检查您想要的最新更改,然后cd
备份到上层存储库,并运行git为每个子模块添加路径/到/子模块
。选项 2:
在上部(最外层)存储库中执行交互式变基:
在交互式变基文件编辑器中,手动删除更新子模块的所有提交。 完成变基。
完成后,手动
cd
进入每个子模块,拉取或检查您想要的最新更改,然后cd
备份到上层存储库,并运行git add path /to/submodule
对于您想要更新为最新更改的每个子模块。完毕。
另请参阅:
How to resolve conflicts with git submodules, in your outer repo containing them
Option 1:
Like the main answer:
Then, when done with the conflict resolution, manually
cd
into each submodule, pull or check out your latest changes you want, thencd
back up into the upper repo, and rungit add path/to/submodule
for each submodule.Option 2:
Do an interactive rebase in the upper (outer-most) repo:
In the interactive rebase file editor, manually delete all commits which updated your submodules. Complete the rebase.
When done, manually
cd
into each submodule, pull or check out your latest changes you want, thencd
back up into the upper repo, and rungit add path/to/submodule
for each submodule you want updated to your latest changes.Done.
See also:
如果你想使用上游版本:
If you want to use the upstream version:
如果有人重新定位并在子模块存储库中进行了
git push --force
,则git submodule update --remote --checkout -f
In case if someone rebased and made
git push --force
in submodule repo, thengit submodule update --remote --checkout -f <submodule>