如何让 git 显示正在跟踪的文件列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15606955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:49:48  来源:igfitidea点击:

How can I make git show a list of the files that are being tracked?

git

提问by RobertL

Using command line git, how can I make git show a list of the files that are being tracked in the repository?

使用命令行 git,如何让 git 显示存储库中正在跟踪的文件列表?

回答by Tuxdude

If you want to list all the files currently being tracked under the branch master, you could use this command:

如果要列出当前在 branch 下跟踪的所有文件master,可以使用以下命令:

git ls-tree -r master --name-only

If you want a list of files that ever existed (i.e. including deleted files):

如果您想要一个曾经存在的文件列表(即包括已删除的文件):

git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'

回答by vonbrand

The files managed by git are shown by git ls-files. Check out its manual page.

git 管理的文件以git ls-files. 查看其手册页。

回答by Nathan

The accepted answer only shows files in the current directory's tree. To show allof the tracked files that have been committed (on the current branch), use

接受的答案仅显示当前目录树中的文件。要显示已提交的所有跟踪文件(在当前分支上),请使用

git ls-tree --full-tree --name-only -r HEAD
  • --full-treemakes the command run as if you were in the repo's root directory.
  • -rrecurses into subdirectories. Combined with --full-tree, this gives you all committed, tracked files.
  • --name-onlyremoves SHA / permission info for when you just want the file paths.
  • HEADspecifies which branch you want the list of tracked, committed files for. You could change this to masteror any other branch name, but HEADis the commit you have checked out right now.
  • --full-tree使命令像在 repo 的根目录中一样运行。
  • -r递归到子目录。结合--full-tree,这将为您提供所有已提交的跟踪文件。
  • --name-only当您只需要文件路径时,删除 SHA / 权限信息。
  • HEAD指定您想要跟踪、提交文件列表的分支。您可以将其更改为master或任何其他分支名称,但这HEAD是您现在已签出的提交。

This is the method from the accepted answer to the ~duplicate question https://stackoverflow.com/a/8533413/4880003.

这是从接受的答案到 ~duplicate 问题https://stackoverflow.com/a/8533413/4880003 的方法

回答by Bloody_fool

You might want colored output with this.

您可能想要彩色输出。

I use this one-liner for listing the tracked files and directories in the current directory of the current branch:

我使用这个单行列出当前分支的当前目录中跟踪的文件和目录:

ls --group-directories-first --color=auto -d $(git ls-tree $(git branch | grep \* | cut -d " " -f2) --name-only)

You might want to add it as an alias:

您可能希望将其添加为别名:

alias gl='ls --group-directories-first --color=auto -d $(git ls-tree $(git branch | grep \* | cut -d " " -f2) --name-only)'

If you want to recursively list files:

如果要递归列出文件:

'ls' --color=auto -d $(git ls-tree -rt $(git branch | grep \* | cut -d " " -f2) --name-only)

And an alias:

还有一个别名:

alias glr="'ls' --color=auto -d $(git ls-tree -rt $(git branch | grep \* | cut -d \" \" -f2) --name-only)"