Git子模块工作流程建议 [英] Git Submodule Workflow Advice

查看:123
本文介绍了Git子模块工作流程建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我几天前开始使用Git。 (晚会非常晚 - 不要骂:))。真正开始习惯基本的命令,想法和工作流程。然而,submodules真的让我的大脑乘坐。我正尝试将代码贡献给 FuelPHP GitHub ,我可以使用一些指导和提示。



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

  // 1:从Fuel的github中克隆存储库。 
git clone git://github.com/fuel/fuel.git

// 2:进入主燃料目录
cd fuel

// 3:初始化子模块(使用子模块数据填充.git / config)
git子模块init

// 4:下载子模块...
git子模块更新

// 5:进入核心目录(这是一个子模块)。
cd fuel / core

// 6:将分支从(* no分支)更改为1.1 / develop
git checkout 1.1 / develop

/ / 7:在文本编辑器中打开随机文件+进行一些小改动(即错字)+保存文件。
sudo gedit classes / autoloader.php

// 8:将此文件添加到临时区域。
git add classes / autoloader.php

// 9:在1.1develop分支下提交此文件。
git commit -mim提交一个子模块

// 10:将新提交推到MY(不是fuel)的github repo(是的,我已经重新命名了回购)。
git push git@github.com:jordanarseno / fuel-core.git

// 11:变化反映在github上,看起来不错。

// 12:退出再次加油。推送子模块的时间单独提交。
cd ../../

// 13:将燃料/核心子模块添加到集结区域。
git add fuel / core

// 14:提交子模块更改。
git commit -m推送子模块,现在推送超级。

// 15:将提交推到MY(不是燃料)的github回购。
git push git@github.com:jordanarseno / fuel.git

具体来说,我的问题是:


  1. 这是使用子模块的正确工作流程吗?这是你会怎么做的?

  2. 为什么git将子模块中的 1.1 / develop 分支拉下来,但将我设置为 *没有分支默认情况下?我可以修改此行为吗?

  3. Fuel子模块的哪个部分告诉git从1.1开始?有其他分支( 1.1 / master 1.0 / develop 等)。

  4. 为什么我们不能在第11步中称呼它?子模块推动正常工作。之后我推超级,因为手动告诉我这是一个好主意。事实上,前往GitHub并看着我的超级,提交了一个提交。然而,这个提交845de87 似乎只是对Fuel的超级不是我的超级。它不应该链接到我的回购,而不是他们的?

  5. 在超级节目中运行 cat .git / config

与所有子模块一起...

  [远程起源] 
fetch = + refs / heads / *:refs / remotes / origin / *
url = git:// github.com / fuel / fuel.git` $ b $在核心子模块中运行



.git config
显示:

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

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



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

解决方案


  1. 是的,正如真正的自然子模块


  2. git子模块是对特定提交(SHA1)的引用,而不是分支,因此您始终处于分离模式第一个(与只读用法兼容)。

    换句话说, git子模块更新检出特定的提交,而不是一个分支的提示。

    .gitmodule 文件将包含子模块回购的引用。并且特定的SHA1将作为特殊提交(模式160000)记录在父回购中。当您 git子模块添加'一个新的子模块时,它会记录当前检出其他回购的SHA1(无论其分支)。

    如果您想进行更改,那么您必须在该子模块repo(现有分支或新建分支)中检出分支:在这两种情况下,您都会将任何新更改推回到该远程回购子模块)。
    另一种方法是 git slave


  3. 请参阅2. git分支中列出的其他分支是您子模块回购中存在的本地分支,包括如果您执行了 git pull ,则每个跟踪分支都有一个本地分支在一个点上。因为父级仍然引用子模块的初始SHA1。

    但是,由于您已对其进行了修改,因此该SHA1需要被更新。

    请记住,子模块本身就是一个git repo ...绝对不会将它用作子模块。因此,需要在父回购库中记录该回购的新状态(唯一一个跟踪其子模块的状态)。

    您的第一个git推送完全是内部操作子模块回购(根本不会被父回购看到)。

    对于父回购,子模块回购是一个黑匣子,只有一个远程地址和一个SHA1 。无论在子模块内执行了什么操作,对父代都没有影响,只会检测子模块树的SHA1的变化。

  4. 使用分叉 / a>可能会帮助

    请参阅
    更改git子模块的远程存储库以更新您的子模块远程URL。


So I started using Git a few days ago. ( Very late to the party - don't scold :) ). Really starting to get comfortable with the basic commands, ideas and workflows. However, submodules are really taking my brain for a ride. I am attempting to contribute code to FuelPHP's GitHub and I could use some guidance and tips.

I am running the following commands in the terminal:

//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

Specifically, my questions are:

  1. Is this the proper workflow for working with submodules? Is it what you would do?
  2. Why does git pull down the 1.1/develop branch in a submodule but set me on *no branch by default? Can I modify this behaviour?
  3. What part of the Fuel submodule tells git to pull 1.1/develop to begin with? There are other branches (1.1/master, 1.0/develop etc..).
  4. Why can't we call it a day at step 11? The submodule push worked fine. I push the super afterwards because the manual tells me it's a good idea. And indeed, heading over to GitHub and looking at MY super, a commit is made. This commit 845de87 however, appears to be just a reference to Fuel's super and not MY super. Shouldn't it link to MY repo and not theirs?
  5. Running cat .git/config in super shows:

Along with all the submodules...

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

Running cat .git config in the core submodule shows:

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

Would it be wise to change these url's to MY own repo on GitHub? Fuel denies pushes anyway. If I perform a submodule update, will they be overwritten?

I've also asked this over on Fuel's Forums, but it's more of a general question and there are more Gitters here... THANKS!

解决方案

  1. Yes, as explained in "true nature of submodules"

  2. a git submodule is a reference to a specific commit (SHA1), not a branch, so you are always in a detach mode a first (which is compatible with a read-only usage).
    In other words, git submodule update checks out a specific commit, rather than the tip of a branch.
    The .gitmodule file will contain the reference of your submodule repo. And the specific SHA1 will be recorded in the parent repo as a special commit (mode 160000). When you 'git submodule add' a new submodule, it records the SHA1 at which that other repo is currently checked out (whatever its branch).
    If you want to make changes, then you must checkout a branch within that submodule repo (an existing branch or a new one: in both cases, you will push any new change back to the remote repo of that submodule).
    An alternative would be git slave.

  3. See 2. The other branch(es) listed in the git branch are the local one existing in your submodule repo, including one local branch for each tracking branch if you did a git pull at one point.

  4. Because the parent still reference the initial SHA1 of the submodule.
    But since you have made modifications in it, that SHA1 needs to be updated.
    Keep in mind that the submodule is a git repo in itself... with absolutely no idea it is used as a submodule. Hence the necessity to record the new state of that repo in the parent repo (the only one keeping track of the state of its submodules).
    Your first git push is entirely an internal operation of the submodule repo (which isn't seen at all by the parent repo).
    For a parent repo, the submodule repo is a "black box", with only a remote address and a SHA1. Whatever is done within the submodule has no consequence on the parent, which will detect only the change of the SHA1 of the submodule tree.

  5. Using forks might help
    See "Changing remote repository for a git submodule" to update your submodule remote URL.

这篇关于Git子模块工作流程建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆