[英]How to stage (git add) all changes and new files except submodules?
[英]How do I `git add -u` except new commits in submodules?
我目前的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
? 我想要实现的是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...
完成 git add -u 后,您需要重置所有子模块路径。
如“在 git 存储库中列出子模块”中所述
git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | xargs git reset --
这将列出所有子模块路径并对每个子模块进行git reset
。
类似的想法,来自这个要点:
for i in `git config -f .gitmodules --get-regexp path | cut -d" " -f2` ; do git reset -- $i ; done
最终解决方案,一个 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
}
(仍有改进的空间,例如检查哪些子模块已经添加到索引中,这样我们就不会git reset
这些。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.