2017-08-30 55 views
0

我有一个带有单个子模块的超级项目。该子模块完全独立于超级项目开发,但这不是我的超级项目设置方式。目前,当子模块的来源得到更新时,如果有人(我)运行git submodule update --recursive --remote,然后将该更新提交给超级项目,则只会更新超级项目。那很愚蠢;我不跟踪任何版本或提交我的超级项目中子模块的散列。我想要的是在我的超级项目中拥有子模块的起源/主人,无论起源/主人是什么。我只想要同步子模块,而不是将子模块提交到我的超级项目中。git子模块:如何保持子模块当前不提交到超级项目?

例如,做一个git clone,为了得到子模块后,我跑git submodule update --init --recursive并获得这样的:

$ git submodule update --init --recursive 
Submodule 'scripts/token' (https://gitserver.company.com/token.git) registered for path 'scripts/token' 
Submodule path 'scripts/token': checked out '93b6bee2031913f563f548883358a65a136bdd88' 

但提交哈希93b6bee2031913f563f548883358a65a136bdd88不是令牌回购的起源/主;那是0f39201818985d21a1f2362ad5b519793bd4f2b6。为了得到这一点,我已经运行另一个git submodule命令:

$ git submodule update --recursive --remote 
Cloning into '/Users/me/superproject/scripts/token'... 
Submodule path 'scripts/token': checked out '0f39201818985d21a1f2362ad5b519793bd4f2b6' 
$ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 

Changes not staged for commit: 
(use "git add <file>..." to update what will be committed) 
(use "git checkout -- <file>..." to discard changes in working directory) 

    modified: scripts/token (new commits) 

没有,我没有“新提交”到上层项目;我刚刚同步了一个子模块。我希望这个工作像一个依赖;我想token>=0.0.1(无论是起源/主),但它似乎是我所拥有的是token=explicit_commit_hash。我不想在我的超级项目中支持版本号或提交子模块标记的哈希值。

UPDATE:换句话说,如果git status说:“跟上时代的”不当地修改运行git submodule update前,然后git submodule update更新子模块后,我还是想git status说“上的最新”没有本地变化。

我在做什么错?

回答

0

我能想到的最接近的近似方式是为你的克隆使用一个别名,一个子模块更新远程克隆(surclone或任何你想调用它的东西)。将以下内容添加到您的.gitconfig文件中。由于shell将尝试解析参数,因此通过git config --global alias.surclone添加它将不起作用。

surclone = "!f() { git clone --recursive ${1} . && git submodule update --remote --recursive --init; }; f" 

您可以扩展命令自动提交(git commit --amend -a -m "Current master version of all submodules"),然后用力将其推送到服务器(git push -f)。这一切都需要添加子模块的时候,你也可以指定分支它是跟踪,或以后添加此,例如,.gitmodules

[submodule "SubmoduleA"] 
    path = SubmoduleA 
    url = [email protected]:some/repo.git 
    branch = master 
+0

我正在寻找的是一切都交给了'git的commit'。我不想让子模块更新甚至被视为修改后的代码。如果'git status'说的是“最新的”,那么在'git submodule update'更新子模块之后,我仍然希望'git status'说“最新”而不需要本地修改。 – DrStrangepork