所以几天前我开始使用 Git。 (聚会已经很晚了——别骂:))。真正开始熟悉基本命令、想法和工作流程。然而,子模块确实让我大吃一惊。我正在尝试贡献代码FuelPHP http://fuelphp.com/'s GitHub https://github.com/fuel我可以使用一些指导和技巧。
我正在终端中运行以下命令:
//1: clone the repository from Fuel's github.
git clone git://github.com/fuel/fuel.git
//2: move into the main fuel directory
cd fuel
//3: initilize the submodules (populate .git/config with submodule data)
git submodule init
//4: download the submodules...
git submodule update
//5: move into the core directory (which is a submodule).
cd fuel/core
//6: change branch from (*no branch) to 1.1/develop
git checkout 1.1/develop
//7: open random file in text editor + make some small change (i.e. typo) + save file.
sudo gedit classes/autoloader.php
//8: add this file to the staging area.
git add classes/autoloader.php
//9: commit this file under 1.1develop branch.
git commit -m "im committing a submodule"
//10: push the new commit to MY (not fuel's) github repo (yes i've renamed the repo).
git push [email protected] /cdn-cgi/l/email-protection:jordanarseno/fuel-core.git
//11: changes are reflected on github, looks good.
//12: back way out to fuel again. time to push the submodule commit separately.
cd ../../
//13: add the fuel/core submodule to the staging area.
git add fuel/core
//14: commit the submodule change.
git commit -m "submodule pushed. pushing super now."
//15: push the commit to MY (not fuel's) github repo.
git push [email protected] /cdn-cgi/l/email-protection:jordanarseno/fuel.git
具体来说,我的问题是:
- 这是使用子模块的正确工作流程吗?这是你会做的吗?
- 为什么 git 会下拉
1.1/develop
在子模块中分支但让我打开*no branch
默认情况下?我可以修改这个行为吗?
- Fuel 子模块的哪一部分告诉 git 首先拉取 1.1/develop?那里are其他分支机构(
1.1/master
, 1.0/develop
etc..).
- 为什么我们不能在第 11 步就结束呢?子模块推送工作正常。后来我推了超级,因为手册告诉我这是个好主意 http://book.git-scm.com/5_submodules.html。事实上,前往 GitHub 并查看我的超级,已做出提交。此提交 845de87 https://github.com/jordanarseno/fuel/tree/1.1/master/fuel然而,似乎只是引用了 Fuel 的 super,而不是 MY super。它不应该链接到我的仓库而不是他们的吗?
- Running
cat .git/config
在超级节目中:
连同所有子模块...
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git://github.com/fuel/fuel.git`
Running cat .git config
在核心子模块中显示:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git://github.com/fuel/core.git
将这些 url 更改为我自己在 GitHub 上的存储库是否明智?无论如何,燃料否认推动。如果我执行子模块更新,它们会被覆盖吗?
我也问过这个问题燃料的论坛 http://fuelphp.com/forums/topics/view/7782,但这更多的是一个一般性问题,而且这里有更多的 Gitters...谢谢!
是的,正如“子模块的真实性质 https://stackoverflow.com/a/1979194/6309"
git 子模块是对特定提交 (SHA1) 的引用,而不是分支,因此您始终首先处于分离模式(与只读用法兼容)。
换句话说,git submodule update
检查特定的提交,而不是分支的提示。
The .gitmodule
文件将包含子模块存储库的引用。并且特定的 SHA1 将作为特殊提交(模式 160000)记录在父存储库中。当你 'git submodule add
' 一个新的子模块,它记录当前签出其他存储库的 SHA1(无论其分支是什么)。
如果要进行更改,则必须签出该子模块存储库中的分支(现有分支或一个新的:在这两种情况下,您都将把任何新的更改推送回该子模块的远程存储库)。
另一种选择是git奴隶 http://gitslave.sourceforge.net/.
请参阅 2. 中列出的其他分支git branch
是子模块存储库中现有的本地分支,每个子模块都包含一个本地分支跟踪分支 https://stackoverflow.com/a/4697054/6309如果你做了一个git pull
在一个点上。
因为父模块仍然引用子模块的初始 SHA1。
但由于您对其进行了修改,因此需要更新 SHA1。
请记住,子模块本身就是一个 git 存储库...完全不知道它被用作子模块。因此,有必要在父存储库中记录该存储库的新状态(唯一一个跟踪其子模块状态的存储库)。
你的第一次 git Push 完全是internal子模块存储库的操作(父存储库根本看不到)。
对于父存储库,子模块存储库是一个“黑匣子”,只有远程地址和 SHA1。无论子模块内做什么,都不会影响父模块,父模块只会检测子模块树 SHA1 的更改。
Using forks http://help.github.com/fork-a-repo/可能有帮助
See "更改 git 子模块的远程存储库 https://stackoverflow.com/a/914090/6309" 更新您的子模块远程 URL。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)