将Git子模块更新为最新的原始提交 [英] Update Git submodule to latest commit on origin

查看:102
本文介绍了将Git子模块更新为最新的原始提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Git子模块的项目。它来自于ssh:// ... URL,并且在提交A上。提交B已被推送到该URL,并且我希望子模块检索提交并更改为提交。



现在,我的理解是, git submodule update 应该这样做,但不是。它不会执行任何操作(无输出,成功退出代码)。下面是一个例子:

  $ mkdir foo 
$ cd foo
$ git init。
在/.../foo/.git/中初始化的空Git仓库
$ git submodule add ssh:// user @ host / git / mod mod
克隆到mod ...
user @ host的密码:hunter2
remote:计数对象:131,完成。
remote:压缩对象:100%(115/115),完成。
remote:合计131(delta 54),重用0(delta 0)
接收对象:100%(131/131),16.16 KiB,完成。
解析三角洲:100%(54/54),完成。
$ git commit -mHello world。
[master(root-commit)565b235] Hello world。
2个文件已更改,4个插入(+),0个删除( - )
创建模式100644 .gitmodules
创建模式160000 mod
#此时,ssh://用户@ host / git / mod改变;子模块也需要改变。
$ git submodule init
子模块'mod'(ssh:// user @ host / git / mod)为路径'mod'注册
$ git子模块更新
$ git子模块sync
同步'mod'的子模块url
$ git submodule update
$ man git-submodule
$ git submodule update --rebase
$ git submodule update
$ echo $?
0
$ git status
#分支大师
没有提交(工作目录清理)
$ git子模块更新模块
$ ...

我也试过 git fetch mod , (但不可能,因为它不提示输入密码!),但是 git log git show code>否认新提交的存在。到目前为止,我只是 rm - 模块并重新添加它,但这在原理上和实践上都是单调乏味的。

解决方案

git submodule update 命令实际上告诉Git你希望你的子模块检查已经在超级项目的索引中指定的提交。如果您希望 将子模块更新为可从其远程获得的最新提交,则需要直接在子模块中执行此操作。



总结:
$ b $ pre $ code $#最初得到子模块
git submodule add ssh:// bla submodule_dir
git子模块init

#时间传递,子模块上游更新
#并且您现在要更新

#更改为子模块目录
cd submodule_dir

#结帐所需的分支
git结帐大师

#更新
git pull

#返回您的项目root
cd ..

#现在子模块处于你想要的状态,所以
git commit -am将子模块更新到submodule_dir


  git submodule foreach git pull origin master 


I have a project with a Git submodule. It is from an ssh://... URL, and is on commit A. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it.

Now, my understanding is that git submodule update should do this, but it doesn't. It doesn't do anything (no output, success exit code). Here's an example:

$ mkdir foo
$ cd foo
$ git init .
Initialized empty Git repository in /.../foo/.git/
$ git submodule add ssh://user@host/git/mod mod
Cloning into mod...
user@host's password: hunter2
remote: Counting objects: 131, done.
remote: Compressing objects: 100% (115/115), done.
remote: Total 131 (delta 54), reused 0 (delta 0)
Receiving objects: 100% (131/131), 16.16 KiB, done.
Resolving deltas: 100% (54/54), done.
$ git commit -m "Hello world."
[master (root-commit) 565b235] Hello world.
 2 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 .gitmodules
 create mode 160000 mod
# At this point, ssh://user@host/git/mod changes; submodule needs to change too.
$ git submodule init
Submodule 'mod' (ssh://user@host/git/mod) registered for path 'mod'
$ git submodule update
$ git submodule sync
Synchronizing submodule url for 'mod'
$ git submodule update
$ man git-submodule 
$ git submodule update --rebase
$ git submodule update
$ echo $?
0
$ git status
# On branch master
nothing to commit (working directory clean)
$ git submodule update mod
$ ...

I've also tried git fetch mod, which appears to do a fetch (but can't possibly, because it's not prompting for a password!), but git log and git show deny the existence of new commits. Thus far I've just been rm-ing the module and re-adding it, but this is both wrong in principle and tedious in practice.

解决方案

The git submodule update command actually tells Git that you want your submodules to each check out the commit already specified in the index of the superproject. If you want to update your submodules to the latest commit available from their remote, you will need to do this directly in the submodules.

So in summary:

# get the submodule initially
git submodule add ssh://bla submodule_dir
git submodule init

# time passes, submodule upstream is updated
# and you now want to update

# change to the submodule directory
cd submodule_dir

# checkout desired branch
git checkout master

# update
git pull

# get back to your project root
cd ..

# now the submodules are in the state you want, so
git commit -am "Pulled down update to submodule_dir"

Or, if you're a busy person:

git submodule foreach git pull origin master

这篇关于将Git子模块更新为最新的原始提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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