问题描述
有一个强大的方法来执行递归深度优先 git submodule foreach
命令?我使用 foreach --recursive
命令来完成这项工作,除了它是宽度优先。这是一个问题,因为如果我有以下结构: - A
- B
- C
提交全部三个, foreach --recursive add -A&& git commit ...
会碰到A,B,C,如果我想让supermodule在那时捕获B的提交,这是有问题的。
我从2008年发现了,但是它看起来并不像任何建议的功能(1.7.9.5)。
我写了一个小的bash函数来做这件事(原谅速记命名):
函数git-sfed(){git submodule foreachgit submodule foreach'$ *'&& $ *; }
使用下面这个fanciful命令测试它似乎是可行的:
git-sfed'python -cimport sys; print sys.argv$ path'
这个命令看起来很健壮吗,还是还有其他常用的现有方法吗?
您可以试试这个
git submodule foreach --recursive | tail -r | sed's /进入//'| xargs -I%cd%; git add -A \& git commit
这个列表(递归地)所有子模块,然后颠倒列表 tail -r
这样你就可以按照你想要的顺序获得目录(子优先),进入目录并做任何你想要的内容。
Is there a robust way to do a recursive depth-first git submodule foreach
command? I am using the foreach --recursive
command which does the job, except it is breadth-first. This is a problem because if I have the following structure:
- A
- B
- C
And I have commits in all three, a foreach --recursive add -A && git commit ...
will hit A, B, C, which is problematic if I want the supermodule to capture the commits of B at that time.
I found this discussion from 2008, but it does not look like any of the suggested features are in the current version of Git that I have (1.7.9.5).
I wrote a small bash function to do this (excuse the shorthand naming):
function git-sfed() { git submodule foreach "git submodule foreach '$*' && $*"; }
And testing it with the following fanciful command seems to work:
git-sfed 'python -c "import sys; print sys.argv" $path'
Does this command seem robust, or are there other common existing methods?
You can try this
git submodule foreach --recursive | tail -r | sed 's/Entering//' | xargs -I% cd % ; git add -A \& git commit
This list (recursively) all the submodules , then reverse the list, tail -r
so you get the directories in the order you want (child first), enter the directory and do what ever you want in it.
这篇关于git submodule foreach - 健壮的方式递归地提交一个子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!