用自己的叉子交换 git 子模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11637175/
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
Swap git submodule with own fork
提问by Svish
I added a submodule to my git repo like this:
我在我的 git repo 中添加了一个子模块,如下所示:
$ git submodule add git://github.com/user/some-library some-library
I've decided I want to create a fork of that library to do some adjustments. How can i swap that submodule so that it points to my own github fork instead?
我决定创建一个该库的分支来做一些调整。如何交换该子模块,使其指向我自己的 github fork?
回答by dbr
The submodules are stored in .gitmodules
:
子模块存储在.gitmodules
:
$ cat .gitmodules
[submodule "ext/google-maps"]
path = ext/google-maps
url = git://git.naquadah.org/google-maps.git
If you edit the url
with a text editor, you need to run the following:
如果url
使用文本编辑器编辑,则需要运行以下命令:
$ git submodule sync
This updates .git/config
which contains a copy of this submodule list (you could also just edit the relevant [submodule]
section of .git/config
manually)
此更新.git/config
包含此子模块列表的副本(您也可以手动编辑相关[submodule]
部分.git/config
)
There might be a way to do it with only git
commands, although the submodule
system seems a bit incomplete (e.g see the instructions to remove a submodule)
可能有一种方法可以仅使用git
命令来完成,尽管submodule
系统似乎有点不完整(例如,请参阅删除子模块的说明)
回答by mcepl
I don't know how long it is true, but certainly even in rather old git 1.8 submodules have remotes. So, you can do
我不知道它是多长时间,但当然即使在相当老的 git 1.8 子模块中也有遥控器。所以,你可以做
cd some-library # this is entering the submodule
git remote -v # just to see what you have; I guess origin only
git remote add myrepo git-URL-of-the-fork
git checkout -b my_new_idea
git push -u myrepo my_new_idea
Now the submodule work with your fork instead of the original repo. You can do normal push, pull, rebase
etc. When your pull request is merged, you can remove the remote with normal git remote remove myrepo
. Of course, all other caveats about working with submodules apply (e.g., you have to commit the change of the submodule as a new commit in the supermodule).
现在子模块与您的 fork 一起工作,而不是原始 repo。你可以做 normalpush, pull, rebase
等。当你的 pull request 被合并后,你可以用 normal 删除远程git remote remove myrepo
。当然,有关使用子模块的所有其他警告都适用(例如,您必须将子模块的更改作为超级模块中的新提交进行提交)。