- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在尝试弄清楚如何获取 git 存储库中所有文件的列表,包括那些包含在子模块中的文件。目前,git ls-files
将提供顶级子模块目录,但不提供子模块中包含的文件。在进一步调查中,我发现使用 git submodule
,您可以递归地找到所有子模块,然后使用 git ls-files
:
git submodule --quiet foreach --recursive "git ls-files"
唯一的问题是结果是来自子模块的路径,但我需要来自 repo 的完整路径。所以对于以下
例如/some/path/to/gitrepo/source/submodule/[file1, file2]
我看到的是:
file1
file2
我想看到的是:
source/submodule/file1
source/submodule/file2
有没有办法做到这一点?在文档中,有一些预定义的变量($name、$path、$sha1 和 $toplevel),但我不确定如何使用这些变量来获得所需的结果。
最佳答案
Git 2.11+(2016 年第 4 季度)可以使用另一种方法
git ls-files --recurse-submodules
参见 commit 75a6315 , commit 07c01b9 , commit e77aa33 , commit 74866d7 (2016 年 10 月 7 日)Brandon Williams (mbrandonw
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 1c2b1f7 ,2016 年 10 月 26 日)
ls-files
: optionally recurse into submodules
"
git ls-files
" learned "--recurse-submodules
" option that can be used to get a listing of tracked files across submodules (i.e. this only works with "--cached
" option, not for listing untracked or ignored files).This would be a useful tool to sit on the upstream side of a pipe that is read with xargs to work on all working tree files from the top-level superproject.
如图in this test ,输出将包括文件的完整路径,从主父存储库开始。
git ls-files
documentation现在包括:
--recurse-submodules
Recursively calls ls-files on each submodule in the repository.
Currently there is only support for the --cached mode.
Git 2.13(2017 年第 2 季度)增加了 ls-files --recurse-submodules
的稳健性:
参见 commit 2cfe66a , commit 2e5d650 (2017 年 4 月 13 日)Jacob Keller (jacob-keller
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 2d646e3 ,2017 年 4 月 24 日)
ls-files
: fixrecurse-submodules
with nested submodules
Since commit e77aa33 ("ls-files: optionally recurse intosubmodules", 2016-10-07, git 2.11)
ls-files
has known how to recurse intosubmodules when displaying files.Unfortunately this fails for certain cases, including when nesting morethan one submodule, called from within a submodule that itself hassubmodules, or when the
GIT_DIR
environemnt variable is set.Prior to commit b58a68c ("
setup
: allow for prefix to be passed togit commands", 2017-03-17, git 2.13-rc0) this resulted in an error indicating that--prefix
and--super-prefix
were incompatible.After this commit, instead, the process loops forever with a
GIT_DIR
setto the parent and continuously reads the parent submodule files and recursing forever.Fix this by preparing the environment properly for submodules when setting up the child process. This is similar to how other commands such as grep behave.
正如 Git 2.29(2020 年第 4 季度)所述,配置 submodule.recurse
将不起作用。
参见 commit 7d15fdb (2020 年 10 月 4 日)Philippe Blain (phil-blain
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 9d19e17 ,2020 年 10 月 5 日)
gitsubmodules doc
: invoke 'ls-files' with '--recurse-submodules'Signed-off-by: Philippe Blain
git ls-files
(man) was never taught to respect thesubmodule.recurse
configuration variable, and it is too late now to change that, but still the command is mentioned in 'gitsubmodules(7)' as if it does respect that config.Adjust the call in 'gitsubmodules(7)' by calling '
ls-files
' with the '--recurse-submodules
' option.
gitsubmodules
现在包含在其 man page 中:
git ls-files --recurse-submodules
[NOTE]
git ls-files
also requires its own--recurse-submodules
flag.
With Git 2.36 (Q2 2022) ,还支持 git ls-files --stage --recurse-submodule
。
在 Git 2.40(2023 年第一季度)中,停止使用 git --super-prefix
并将其使用范围缩小到 submodule--helper。
参见 commit 4002ec3 , commit f5a6be9 , commit 04f1fab , commit 99a32d8 , commit 677c981 , commit bb61a96 , commit f0a5e5a , commit 49eb1d3 (2022 年 12 月 20 日)Ævar Arnfjörð Bjarmason (avar
) .
参见 commit 0d1806e (2022 年 12 月 20 日)Glen Choo (chooglen
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit d4c5400 ,2023 年 1 月 5 日)
read-tree
: add "--super-prefix" option, eliminate globalSigned-off-by: Ævar Arnfjörð Bjarmason
The "
--super-prefix
" option to "git
" was initially added in commit 74866d7 ("git
: make super-prefix option", 2016-10-07, Git v2.11.0-rc0 -- merge listed in batch #11) for:
- use with "
ls-files
" (commit e77aa33 ("ls-files
: optionally recurse into submodules", 2016-10-07, Git v2.11.0-rc0 -- merge listed in batch #11)), and shortly thereafter- "
submodule--helper
" (commit 89c8626 ("submodule helper: support super prefix", 2016-12-08, Git v2.12.0-rc0 -- merge listed in batch #5)) and- "
grep
" (0281e48 ("grep
: optionally recurse into submodules", 2016-12-16, Git v2.12.0-rc0 -- merge listed in batch #6)).It wasn't until commit 3d41542 ("
unpack-trees
: support super-prefix option", 2017-01-17, Git v2.12.0-rc0 -- merge) that "read-tree
" made use of it.At the time it made sense, but since then we've made "
ls-files
" recurse in-process in commit 188dce1 ("ls-files
: use repository object", 2017-06-22, Git v2.14.0-rc0 -- merge listed in batch #14), "grep
" in commit f9ee2fc ("grep
: recurse in-process using 'struct repository'", 2017-08-02, Git v2.15.0-rc0 -- merge listed in batch #2), and finally "submodule--helper
" in the preceding commits.Let's also remove it from "
read-tree
", which allows us to remove the option to "git
" itself.We can do this because the only remaining user of it is the submodule API, which will now invoke "
read-tree
" with its new "--super-prefix
" option.
It will only do so when the "submodule_move_head()
" function is called.That "
submodule_move_head()
" function was then only invoked by "read-tree
" itself, but now rather than setting an environment variable to pass "--super-prefix
" betweencmd_read_tree()
we: - Set a new"super_prefix"
in "structunpack_trees_options"
.
git
现在包含在其 man page 中:
[--config-env==] []
关于GIT:查找文件列表(例如使用 git ls-files),包括子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36848544/
我有这个 html 代码: HELLO WORLD! X V HELLO WORLD! X V 我想按 X(类关闭)将父 div 的高度更改为 20px 并显示 V(类打开),但在每个 d
在会计应用程序的许多不同实现中,有两种主要的数据库设计方法来保存日志和分类帐数据。 只保留 Journal 信息,然后 Ledger 只是 Journal 的一个 View (因为 journal 总
我想在另一个子里面有一个子, sub a { sub b { } } 我想为每次调用 sub b 创建一个新的 sub a 实例。有没有办法在 Perl 中做到这一点? 当我运行上面的
我有一些代码正在查找重复项并突出显示单元格: Private Sub cmdDups_Click() Dim Rng As Range Dim cel As Range Set Rng = ThisW
可能有一个简单的解决方案,但我很难过。 我有一个包含一个 ID 字段的主表。在两个可能的字段中有一个具有该 ID 的子表。想象一个由选手 A 和选手 B 组成的 double 队。Master 表将有
假设我有一个包含对象的数组: [ { "id": "5a97e047f826a0111b754beb", "name": "Hogwarts", "parentId": "
我正在尝试对 MySQL 数据库表执行一对父/子模型的批量插入,但似乎无法使用标准的 ActiveRecord 功能来完成。所以,我尝试了 activerecord-import gem,但它也不支持
我有一个带有多个子类的父抽象类。最终,我希望通过 GUI 中的进度条显示子类中完成的进度。 我目前所做的,我意识到这是行不通的,是在父类中声明为每个子类将覆盖的虚拟方法的事件方法定义。所以像: pub
是否可以通过键数组在对象中设置变量?例如我有这个对象: var obj = {'outer': {'inner': 'value'} }; 并希望设置由键数组选择的值: var keys = ['ou
我有一个名为 companies 的 MySQL 表,如下所示: +---------+-----------+-----------+ | id_comp | comp_name | id_pare
我正在尝试使用 sublime text 在 sublime text 上的 ionic 上打开我的第一个应用程序。它给了我一个“找不到命令”的错误。如何修复? 我试过这些命令: sudo rm -r
不好意思问,但我正在使用 webapp2,我正在设计一个解决方案,以便更容易定义路由 based on this google webapp2 route function .但这完全取决于能够在子级
我有代表树的数字字符串(我不知道是否有官方名称): 012323301212 上面的例子代表了 2 棵树。根用 0 表示。根的直接子代为“1”,“1”的直接子代为“2”,依此类推。我需要将它们分组到由
是否可以在当前 Activity 之上添加 Activity 。例如,假设我单击一个按钮,然后它将第二个 Activity 添加到当前 Activity 。而第二个 Activity 只覆盖了我当前
我很难思考如何为子资源建模。 以作者的书籍为例。你可以有 N 本书,每本书只有一位作者。 /books GET /books POST /books/id PUT /books/id DELETE 到
有人可以向我解释以下内容(python 2.7) 来自已解析文件的两个字符串数字: '410.9''410.9 '(注意尾随空格) A_LIST = ['410.9 '] '410.9' in '41
背景 在 PowerShell 中构建 hash table 是很常见的通过特定属性快速访问对象,例如以 LastName 为基础建立索引: $List = ConvertFrom-Csv @' I
我真的很难弄清楚如何调用嵌套 Polymer Web 组件的函数。 这是标记: rise-distribution组件有 canPlay我想从 rise-playlist
我写了一个小工具转储(以 dot 格式)一个项目的依赖关系图,其中所有位于同一目录中的文件都聚集在一个集群中。当我尝试生成包含相应图形的 pdf 时,dot开始哭: 命令 dot -Tpdf trim
给定一个 CODE ref,是否可以: 访问该 CODE ref 的解析树 通过指定 CODE ref 的解析树来创建一个新的 CODE ref,该解析树可以包含在 1 中返回的解析树的元素 通常我们
我是一名优秀的程序员,十分优秀!