[英]How do I `git add -u` except new commits in submodules?
My current git status
is:我目前的
git status
是:
modified: Gemfile
modified: Gemfile.lock
modified: ... many more files
modified: submodule_1 (new commits)
modified: submodule_2 (new commits)
modified: ... many more updated submodules ...
git add -u
except new commits in submodules?git add -u
? What I want to achieve is an equivalent of git add -u
, then git reset HEAD submodule_1 submodule_2 ... submodule_n
, or an equivalent of git add -u Gemfile Gemfile.lock ...all other files that are not submodules...
我想要实现的是
git add -u
的等价物,然后git reset HEAD submodule_1 submodule_2 ... submodule_n
,或git add -u Gemfile Gemfile.lock ...all other files that are not submodules...
Once git add -u is done, you would need to reset all submodule paths.完成 git add -u 后,您需要重置所有子模块路径。
As documented in " List submodules in a git repository "如“在 git 存储库中列出子模块”中所述
git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | xargs git reset --
This would list all submodule paths and do a git reset
on each one.这将列出所有子模块路径并对每个子模块进行
git reset
。
A similar idea, from this gist :类似的想法,来自这个要点:
for i in `git config -f .gitmodules --get-regexp path | cut -d" " -f2` ; do git reset -- $i ; done
Final solution, a bashrc/zshrc funnction that does git add -u
and resets submodules:最终解决方案,一个 bashrc/zshrc 函数,它执行
git add -u
并重置子模块:
gitaddus() {
git add -u
git config -f .gitmodules --get-regexp path | awk '{ print $2 }' | xargs git reset -- >/dev/null
git status
}
(There's still a room for improvements, eg check which submodules are already added to the index so we don't git reset
these.) (仍有改进的空间,例如检查哪些子模块已经添加到索引中,这样我们就不会
git reset
这些。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.