2012-02-23 80 views
8

所以我几天前开始使用Git。 (晚会很晚 - 不要骂:))。真正开始习惯基本的命令,想法和工作流程。然而,submodules真的让我的大脑乘坐。我正在尝试向FuelPHPGitHub提供代码,我可以使用一些指导和提示。Git子模块工作流程建议

我在终端运行以下命令:

//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]: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]:jordanarseno/fuel.git 

具体来说,我的问题是:

  1. 这是与子模块工作的正确的工作流程?你会做什么?
  2. 为什么git将子模块中的1.1/develop分支拉下来,但默认情况下设置为*no branch?我可以修改这种行为吗?
  3. Fuel子模块的哪个部分告诉git拉1.1 /开发? 其他分支(1.1/master,1.0/develop等)。
  4. 为什么我们不能在第11步中称呼它?子模块推动正常工作。之后我推超,因为手册tells me it's a good idea。事实上,前往GitHub并看着我的超级,提交了一个提交。然而,它似乎只是Fuel的超级参考,而不是我的超级参考。它不应该链接到我的回购,而不是他们的?
  5. 运行在超显示cat .git/config

随着所有的子模块...

[remote "origin"] 
fetch = +refs/heads/*:refs/remotes/origin/* 
url = git://github.com/fuel/fuel.git` 

核心子模块运行cat .git config显示:

[remote "origin"] 
fetch = +refs/heads/*:refs/remotes/origin/* 
url = git://github.com/fuel/core.git 

难道是明智的更改这些网址为我自己在GitHub上的回购?无论如何,燃料否认推动。如果我执行子模块更新,它们是否会被覆盖?

我也在Fuel's Forums上问过这个问题,但这是更常见的问题,这里还有更多的Gitters ......谢谢!

回答

10
  1. 是的,在“true nature of submodules

  2. 一个git子模块的引用到一个特定的提交(SHA1),而不是一个分支解释,所以你总是在分离模式中的第一(这与只读用法兼容)。
    换句话说,git submodule update检出了一个特定的提交,而不是分支的提示。
    .gitmodule文件将包含您的子模块回购的参考。并且特定的SHA1将作为特殊提交(模式160000)记录在父回购中。当'git submodule add'是一个新的子模块时,它记录当前检出其他回购的SHA1(无论其分支)。
    如果您想进行更改,那么您必须签出该子模块回购(现有分支或新的:在这两种情况下,您将推回任何新的变化回到该子模块的远程回购)分支。
    另一种方法是git slave

  3. 见2. git branch列出的其他分支(ES)是当地的一个存在于你的子模块的回购协议,其中包括一个地方分支每个tracking branch,如果你在一个点上做了git pull

  4. 由于父级仍然引用子模块的初始SHA1。
    但是由于您已对其进行了修改,因此需要更新SHA1。
    请记住,子模块本身是一个git回购......绝对不会将它用作子模块。因此有必要在回购协议中记录该回购协议的新状态(唯一一个跟踪其子模块的状态)。
    你的第一个git推动完全是内部操作的子模块回购(根本没有看到父回购)。
    对于父回购,子模块回购是一个“黑匣子”,只有一个远程地址和一个SHA1。无论在子模块内执行了什么操作,对父代都没有影响,只会检测子模块树的SHA1的变化。

  5. 使用forks可能有助于
    请参阅 “Changing remote repository for a git submodule” 更新你的子模块的远程URL。

+0

非常感谢!优秀的帖子在其他线程。重新:2;如何找到子模块引用的特定提交?您说过“必须在该子模块回购中检出分支” - 它必须是*现有*分支吗?我可以创造我自己的,并从那里工作耶?回复:3;在子模块中运行'git branch'会返回'* no branch'等。这些'别人'从哪里来,是我想知道的。回复:4;运行第二个git push应该已经完成​​了这个..你说它失败了吗?回复:5;是的,这是主意。叉,然后更改网址。 git submodule update会覆盖吗? – 2012-02-23 12:08:39

+0

@JordanArsenault:我编辑了我的答案以解决您的评论:http://stackoverflow.com/posts/9411932/revisions – VonC 2012-02-23 13:44:33