简体   繁体   English

用自己的fork交换git子模块

[英]Swap git submodule with own fork

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呢?

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 ,其中包含此子模块列表的副本(您也可以手动编辑.git/config的相关[submodule]部分)

There might be a way to do it with only git commands, although the submodule system seems a bit incomplete (eg see the instructions to remove a submodule ) 可能有一种方法只使用git命令,尽管submodule系统似乎有点不完整(例如,请参阅删除子模块的说明

I don't know how long it is true, but certainly even in rather old git 1.8 submodules have remotes. 我不知道这是多久,但即使在相当古老的git 1.8子模块中也有遥控器。 So, you can do 所以,你可以做到

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. 现在子模块使用你的fork而不是原始的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 . 你可以做普通的push, pull, rebase等。当你的拉请求合并时,你可以用普通的git remote remove myrepo Of course, all other caveats about working with submodules apply (eg, you have to commit the change of the submodule as a new commit in the supermodule). 当然,关于使用子模块的所有其他警告都适用(例如,您必须将子模块的更改作为超级模块中的新提交进行提交)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM