git submodule foreach - 首先递归提交子模块的稳健方法? [英] git submodule foreach - Robust way to recursively commit a child module first?

查看:30
本文介绍了git submodule foreach - 首先递归提交子模块的稳健方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种稳健的方法来执行递归深度优先 git submodule foreach 命令?我正在使用 foreach --recursive 命令来完成这项工作,但它是广度优先的.这是一个问题,因为如果我有以下结构:

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

    而且我在所有三个中都提交了一个 foreach --recursive add -A &&git commit ... 会命中 A、B、C,如果我想让超级模块在那个时候捕获 B 的提交,这是有问题的.

    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.

    我在 2008 年发现了这个讨论,但看起来没有任何建议的功能在我拥有的当前 Git 版本 (1.7.9.5).

    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).

    我写了一个小的 bash 函数来做到这一点(请原谅简写命名):

    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?

    推荐答案

    你可以试试这个

    git submodule  foreach --recursive  |  tail  -r | sed 's/Entering//' | xargs -I% cd % ; git add -A & git commit
    

    这个列表(递归地)所有子模块,然后反转列表,tail -r 这样你就可以按照你想要的顺序(子项优先)获得目录,进入目录并做你想做的事情想要在里面.

    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 - 首先递归提交子模块的稳健方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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