如何管理与 git 子模块的冲突?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/826715/
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
How do I manage conflicts with git submodules?
提问by Tyler
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.
我有一个 git 超级项目,它引用了几个子模块,我正在尝试锁定一个工作流,以便我的其他项目成员可以在其中工作。
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.)
对于这个问题,假设我的超级项目被调用supery
,子模块被调用subby
。(然后是我正在尝试做的事情的简化......我实际上并没有将分支用于版本,但我认为最容易提出问题。)
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
.
我的 master 分支将 git 项目supery
的标签作为子模块引用。的分支叫,改变了子模块的参考点来标记的。v1.0
subby
supery
one.one
v1.1
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.
我可以在这些分支中的每一个中顺利工作,但是如果我尝试one.one
使用来自分支的更改来更新分支,master
我会收到一些冲突,但我不知道如何解决它们。
Basically after running a git pull . master
while in the subby
branch, it looks like it creates additional submodules.
基本上在分支中运行一段git pull . master
时间后subby
,它看起来像是创建了额外的子模块。
Before the pull/merge, I get the desired response from git submodule
from the one.one
branch:
在拉/合并之前,我git submodule
从one.one
分支获得所需的响应:
$ 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
:
但是在 pull 之后,它会在我运行时添加额外的子模块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?
如何删除/忽略不需要的子模块引用并提交我的冲突和更改?或者是否有一个参数可以与我的原件一起使用,git pull
它会忽略我的子模块?
采纳答案by Jesse Hallett
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
and one.one
branches of supery
contain different refs for the subby
submodule, when you merge changes from master
git does not know which ref - v1.0
or v1.1
- should be kept and tracked by the one.one
branch of supery
.
我以前从未见过那个确切的错误。但我对你遇到的麻烦有一个猜测。它看起来像,因为master
和one.one
分支supery
包含不同裁判的subby
子模块,当你从合并修改master
混帐不知道哪个裁判-v1.0
或v1.1
-应由保存和跟踪one.one
的分支supery
。
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 resetcommand.
如果是这种情况,那么您需要选择所需的引用并提交该更改以解决冲突。这正是您使用reset命令所做的。
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.
这是在项目的不同分支中跟踪子模块的不同版本的一个棘手方面。但是子模块 ref 就像您项目的任何其他组件一样。如果两个不同的分支在连续合并后继续跟踪相同的各自子模块引用,那么 git 应该能够计算出模式,而不会在未来的合并中引发合并冲突。另一方面,如果频繁切换子模块引用,您可能不得不忍受很多冲突解决。
回答by Tyler
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:
好吧,它不是在技术上管理与子模块的冲突(即:保留这个但不保留那个),但我找到了一种继续工作的方法......我所要做的就是注意我的git status
输出并重置子模块:
git reset HEAD subby
git commit
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).
这会将子模块重置为预拉提交。在这种情况下,这正是我想要的。在我需要将更改应用于子模块的其他情况下,我将使用标准子模块工作流程(结帐主模块、下拉所需标签等)来处理这些更改。
回答by Emma Burrows
I struggled a bit with the answers on this question and didn't have much luck with the answers in a similar SO posteither. 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:
我对这个问题的答案有点挣扎,并且在类似的 SO 帖子中也没有多少运气。所以这对我有用 - 请记住,在我的情况下,子模块由不同的团队维护,因此冲突来自 master 和我正在处理的项目的本地分支中的不同子模块版本:
- Run
git status
- make a note of the submodule folder with conflicts Reset 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:
cd path/to/submodule git submodule foreach git pull origin SUBMODULE-BRANCH-NAME
And now you can
commit
that and get back to work.
- 运行
git status
- 记下有冲突的子模块文件夹 将子模块重置为当前分支中最后提交的版本:
git reset HEAD path/to/submodule
此时,您有一个无冲突版本的子模块,您现在可以将其更新到子模块存储库中的最新版本:
cd path/to/submodule git submodule foreach git pull origin SUBMODULE-BRANCH-NAME
现在您可以
commit
这样做并重新开始工作。
回答by hellatan
First, find the hash you want to your submodule to reference. then run
首先,找到您希望子模块引用的哈希值。然后运行
~/supery/subby $ git co hashpointerhere
~/supery/subby $ cd ../
~/supery $ git add subby
~/supery $ git commit -m 'updated subby reference'
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.
这对我有用,可以让我的子模块获得正确的哈希引用,并继续我的工作而不会发生任何进一步的冲突。
回答by marathon
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 rebase -i origin/master
一个分支上遇到了这个问题。我想采用子模块 ref 的主版本,所以我只是做了:
git reset master path/to/submodule
git reset master path/to/submodule
and then
进而
git rebase --continue
git rebase --continue
That solved the problem for me.
那为我解决了问题。
回答by Mithun Das
Got help from this discussion. In my case the
从这个讨论中得到了帮助。在我的情况下
git reset HEAD subby
git commit
worked for me :)
对我来说有效:)
回答by Kjeld Flarup
Well In my parent directory I see:
那么在我的父目录中,我看到:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
So I just did this
所以我只是做了这个
git reset HEAD linux