首页 > 解决方案 > 如果有未提交的更改,是否可以将 git 子模块更新为自动存储?

问题描述

假设我有一个已经在本地和远程更改的 git 项目,所以它已经过时了。

如果我想在不破坏本地工作的情况下升级到最新的远程代码。Git 可以使用以下命令自动完成:

git pull --rebase --autostash

不幸的是,它仅适用于根模块,适用于 git 子模块。我尝试了以下选项:

git submodule foreach git fetch
git submodule update --init --recursive
# git report error:
# Cannot rebase: Your index contains uncommitted changes.
# Please commit or stash them

git submodule foreach git fetch
git submodule update --init --recursive --autostash
# git report syntax error

git submodule foreach git fetch
git submodule update --init --recursive --force
# git destroy local changes

使子模块的行为类似于根模块的正确方法是什么?

标签: gitgit-submodulesgit-stash

解决方案


推荐阅读