12

所以我几天前开始使用Git。(聚会很晚——别骂 :))。真正开始熟悉基本的命令、想法和工作流程。然而,子模块真的让我大吃一惊。我正在尝试向FuelPHPGitHub贡献代码,我可以使用一些指导和技巧。

我在终端中运行以下命令:

//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 git@github.com: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 git@github.com:jordanarseno/fuel.git

具体来说,我的问题是:

  1. 这是使用子模块的正确工作流程吗?这是你会做的吗?
  2. 为什么 git 拉下1.1/develop子模块中的分支但*no branch默认设置我?我可以修改这种行为吗?
  3. Fuel 子模块的哪一部分告诉 git 从 1.1/develop 开始?还有其他分支(1.1/master1.0/develop)。
  4. 为什么我们不能在第 11 步收工?子模块推送工作正常。之后我推了超级,因为手册告诉我这是个好主意。事实上,前往 GitHub 并查看 MY super,提交了一个。然而,这个提交 845de87似乎只是对 Fuel 的 super 而不是 MY super 的引用。它不应该链接到我的回购而不是他们的吗?
  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

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

我也在Fuel 的论坛上问过这个问题,但这更像是一个普遍的问题,这里有更多的 Gitters……谢谢!

4

1 回答 1

15
  1. 是的,如“子模块的真实性质”中所述

  2. git 子模块是对特定提交 (SHA1) 的引用,而不是分支,因此您始终首先处于分离模式(与只读用法兼容)。
    换句话说,git submodule update检查一个特定的提交,而不是一个分支的尖端。
    .gitmodule文件将包含您的子模块 repo 的引用。并且特定的 SHA1 将作为特殊提交(模式 160000)记录在父 repo 中。当你' git submodule add'一个新的子模块时,它会记录当前签出其他 repo 的 SHA1(无论它的分支是什么)。
    如果要进行更改,则必须签出该子模块存储库中的分支(现有分支或新分支:在这两种情况下,您都将任何新更改推送回该子模块的远程存储库)。
    另一种选择是git slave

  3. 请参阅 2。 中列出的其他分支是子模块存储库中存在的本地分支,如果您曾经做过一个git branch,则包括每个跟踪分支git pull的一个本地分支。

  4. 因为父级仍然引用子模块的初始 SHA1。
    但是由于您已经对其进行了修改,因此需要更新 SHA1。
    请记住,子模块本身就是一个 git repo……绝对不知道它被用作子模块。因此有必要在父 repo 中记录该 repo 的新状态(唯一一个跟踪其子模块状态的)。
    您的第一个 git push 完全是子模块 repo 的内部操作(父 repo 根本看不到)。
    对于父 repo,子模块 repo 是一个“黑匣子”,只有一个远程地址和一个 SHA1。子模块内所做的任何事情都不会对父模块产生任何影响,它只会检测到子模块树的 SHA1 的变化。

  5. 使用分叉可能会有所帮助,
    请参阅“更改 git 子模块的远程存储库”以更新您的子模块远程 URL。

于 2012-02-23T11:15:35.490 回答