git 列出本地git repo中的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8533202/
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 12:31:57  来源:igfitidea点击:

List files in local git repo?

git

提问by Daniel Holm

I'm using Sparkleshare, which uses Git to sync files between my laptop and my backup server.

我正在使用 Sparkleshare,它使用 Git 在我的笔记本电脑和我的备份服务器之间同步文件。

Now I want to be able to browse in the files and dirs that I've uploaded to my server, but I do not know how?

现在我希望能够浏览我上传到我的服务器的文件和目录,但我不知道如何?

I understand that Git uses some sort of special file hierarchy and that I cannot just list my files, right?

我知道 Git 使用某种特殊的文件层次结构,我不能只列出我的文件,对吗?

But how would I have to do to list them and browse my files?

但是我该怎么做才能列出它们并浏览我的文件?

回答by karlphillip

This command:

这个命令:

git ls-tree --full-tree -r --name-only HEAD

lists all of the already committed files being tracked by your git repo.

列出您的 git repo 正在跟踪的所有已提交的文件。

回答by amadillu

Try this command:

试试这个命令:

git ls-files 

This lists all of the files in the repository, including those that are only staged but not yet committed.

这列出了存储库中的所有文件,包括那些仅暂存但尚未提交的文件。

http://www.kernel.org/pub/software/scm/git/docs/git-ls-files.html

http://www.kernel.org/pub/software/scm/git/docs/git-ls-files.html

回答by Jaime Montoya

git ls-tree --full-tree -r HEADand git ls-filesreturn all files at once. For a large project with hundreds or thousands of files, and if you are interested in a particular file/directory, you may find more convenient to explore specific directories. You can do it by obtaining the ID/SHA-1 of the directory that you want to explore and then use git cat-file -p [ID/SHA-1 of directory]. For example:

git ls-tree --full-tree -r HEADgit ls-files一次返回所有文件。对于包含数百或数千个文件的大型项目,如果您对特定文件/目录感兴趣,您可能会发现探索特定目录更方便。您可以通过获取要浏览的目录的 ID/SHA-1 来实现,然后使用git cat-file -p [ID/SHA-1 of directory]. 例如:

git cat-file -p 14032aabd85b43a058cfc7025dd4fa9dd325ea97
100644 blob b93a4953fff68df523aa7656497ee339d6026d64    glyphicons-halflings-regular.eot
100644 blob 94fb5490a2ed10b2c69a4a567a4fd2e4f706d841    glyphicons-halflings-regular.svg
100644 blob 1413fc609ab6f21774de0cb7e01360095584f65b    glyphicons-halflings-regular.ttf
100644 blob 9e612858f802245ddcbf59788a0db942224bab35    glyphicons-halflings-regular.woff
100644 blob 64539b54c3751a6d9adb44c8e3a45ba5a73b77f0    glyphicons-halflings-regular.woff2

In the example above, 14032aabd85b43a058cfc7025dd4fa9dd325ea97is the ID/SHA-1 of the directory that I wanted to explore. In this case, the result was that four files within that directory were being tracked by my Git repo. If the directory had additional files, it would mean those extra files were not being tracked. You can add files using git add <file>...of course.

在上面的示例中,14032aabd85b43a058cfc7025dd4fa9dd325ea97是我想要探索的目录的 ID/SHA-1。在这种情况下,结果是我的 Git 存储库跟踪了该目录中的四个文件。如果目录有其他文件,则意味着没有跟踪这些额外文件。您git add <file>...当然可以使用添加文件。