GIT:找到包含子模块的文件列表(例如,使用git ls-files) [英] GIT: finding a list of files (e.g. using git ls-files) including submodules

查看:647
本文介绍了GIT:找到包含子模块的文件列表(例如,使用git ls-files)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图弄清楚如何获得包含在子模块中的所有文件在git仓库中的列表。目前, git ls-files 将提供顶级子模块目录,但不包含子模块中包含的文件。在进一步的调查中,我发现使用 git submodule ,您可以递归地查找所有子模块,然后执行 git ls-files

  git submodule --quiet foreach --recursivegit ls-files
code>

唯一的问题是结果是来自子模块的路径,但我需要从回购的完整路径。因此,对于以下



例如。 / some / path / to / gitrepo / source / submodule / [file1,file2]

我看到的是:

  file1 
file2

我会喜欢看到的是:

pre $源$ /源模块/文件1 $ b $源/子模块/文件2

有没有办法做到这一点?从文档中,有一些预先定义的变量($ name,$ path,$ sha1和$ toplevel),但我不确定如何使用它们来获得所需的结果。

$ b

  git ls-files --recurse-submodules 

请参阅 commit 75a6315 commit 07c01b9 提交e77aa33 commit 74866d7 (2016年10月7日)作者: Brandon Williams( mbrandonw

(由 Junio C Hamano - gitster - in commit 1c2b1f7 ,2016年10月26日)



< blockquote>

ls-files :可选递归到子模块中

git ls-files learned - recurse-submodules 选项,可用于获取子模块中已跟踪文件的列表(即这只适用于 - 缓存选项,不适用于列出未跟踪或忽略的文件)。

这是一个非常有用的工具,它可以在xargs读取的管道的上游端处理来自顶层超级项目的所有工作树文件。 / p>

如图所示在此测试中,输出将包含文件的完整路径,从主父回购开始。



git ls-files 文档现在包括:

   - 递归子模块




递归调用每个子模块上的ls文件在存储库中。
目前仅支持--cached模式。






Git 2.13(Q2 2017)添加到 ls-files --recurse-submodules 健壮性:



请参阅 commit 2cfe66a 提交2e5d650 (2017年4月13日)作者: Jacob Keller( jacob -keller

(由 Junio合并C Hamano - gitster - commit 2d646e3 ,2017年4月24日)


ls-files <因为commit :fix recurse-submodules 嵌套子模块



//github.com/git/git/commit/e77aa336f116e8ff8a72d034494b3a476b78c3eerel =noreferrer> e77aa33 (ls-files:可选递归到
子模块,2016-10-07,git 2.11) ls-files 已知如何递归到

$ b

不幸的是,在某些情况下,包括嵌套多个
而不是一个子模块时,该子模块本身具有
子模块,或者当设置 GIT_DIR environemnt变量时。



提交之前 b58a68c setup :允许前缀通过到
git命令,2017-03-17,git 2.13-rc0)这导致了一个错误,指出
- 前缀 - 超前缀是不兼容的。



在这个提交之后,进程会永远循环一个 GIT_DIR
设置为父级,并不断读取父级子模块文件并永久递归。



通过在设置子进程时适当地为子模块准备环境来解决此问题。这与其他命令(如grep)的行为类似。



I've been trying to figure out how to get a list of all files in a git repo including those contained within submodules. Currently, git ls-files will provide the top level submodule directory but not the files contained within the submodule. On further investigation, I found that using git submodule, you can recursively find all of the submodules and then go a git ls-files using:

git submodule --quiet foreach --recursive "git ls-files"

The only problem with this is that the results are the path from the submodule but I need the full path from the repo. So for the following

e.g. /some/path/to/gitrepo/source/submodule/[file1, file2]

What I see is:

file1
file2

What I would like to see is:

source/submodule/file1
source/submodule/file2

Is there a way to do this? From the documentation, there are some pre-defined variables ($name, $path, $sha1 and $toplevel) but I'm not sure how to use these to get the desired results.

解决方案

Another approach is possible with Git 2.11+ (Q4 2016)

git ls-files --recurse-submodules

See commit 75a6315, commit 07c01b9, commit e77aa33, commit 74866d7 (07 Oct 2016) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit 1c2b1f7, 26 Oct 2016)

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.

As shown in this test, the output would include the full path of the file, starting from the main parent repo.

The git ls-files documentation now includes:

--recurse-submodules

Recursively calls ls-files on each submodule in the repository.
Currently there is only support for the --cached mode.


Git 2.13 (Q2 2017) adds to the ls-files --recurse-submodules robustness:

See commit 2cfe66a, commit 2e5d650 (13 Apr 2017) by Jacob Keller (jacob-keller).
(Merged by Junio C Hamano -- gitster -- in commit 2d646e3, 24 Apr 2017)

ls-files: fix recurse-submodules with nested submodules

Since commit e77aa33 ("ls-files: optionally recurse into submodules", 2016-10-07, git 2.11) ls-files has known how to recurse into submodules when displaying files.

Unfortunately this fails for certain cases, including when nesting more than one submodule, called from within a submodule that itself has submodules, or when the GIT_DIR environemnt variable is set.

Prior to commit b58a68c ("setup: allow for prefix to be passed to git 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 set to 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:找到包含子模块的文件列表(例如,使用git ls-files)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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