【问题标题】:What's the status of my git submodule, and how can I clean it up?我的 git 子模块的状态是什么,我该如何清理它?
【发布时间】:2012-03-26 16:42:08
【问题描述】:

作为一个相对子模块的菜鸟,我想从它的起源更新我的子模块,并且做到了:

git pull

这导致:

remote: Counting objects: 111, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 57 (delta 54), reused 57 (delta 54)
Unpacking objects: 100% (57/57), done.
From github.com:eteanga/smarty
   8e9a011..818ab3e  master     -> origin/master
You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

尝试修复:

git pull origin master

输出:

From github.com:eteanga/smarty
 * branch            master     -> FETCH_HEAD
Updating 8e9a011..818ab3e
Fast-forward
[snip]

现在看来我确实得到了更新的代码,但是我目前没有在任何分支上工作。

我应该怎么做才能正确更新我的子模块,我应该怎么做才能修复这个当前状态?

【问题讨论】:

    标签: git git-submodules git-pull


    【解决方案1】:

    git submodule update之后,将子模块中的HEAD设置为超级项目中保存的子模块commit-hash。如果您想重置子模块中的HEAD 以跟踪origin/master 中的新提交,您首先必须签出到master,然后拉取更改:

    在子模块目录中:

    git checkout master
    git pull origin master
    

    【讨论】:

    • 非常感谢,这似乎奏效了。我是否必须在签出此主存储库的每台机器上进行此更新,以让他们提取最新的子模块代码?
    • 我遇到了同样的问题,看来您必须为每个签出的 repo 中的每个子模块执行此操作。我想找到一个解决方案,我可以使用git clone --recursive 克隆我的主存储库,然后根据需要为每个子模块推送和拉取更改。有人知道怎么做吗?
    • 打我:在git submodule foreach &lt;command&gt; 似乎之后运行上面答案中的两个命令就可以了。虽然不确定任何潜在的副作用......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多