列出本地git仓库中的文件?

本文介绍了如何在使用Sparkleshare与Git同步文件时,浏览和列出上传到服务器的文件和目录。通过理解Git的特殊文件层次结构,可以使用特定的Git命令如`git ls-files`和`git checkout`来查看和访问这些文件。
摘要由CSDN通过智能技术生成

本文翻译自:List files in local git repo?

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? 但是如何列出它们并浏览我的文件呢?


#1楼

参考:https://stackoom.com/question/ZnsI/列出本地git仓库中的文件


#2楼

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


#3楼

git ls-tree --full-tree -r HEAD and git ls-files return all files at once. git ls-tree --full-tree -r HEADgit ls-files一次返回所有文件。 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] . 您可以通过获取要探索的目录的ID / SHA-1来执行此操作,然后使用git cat-file -p [ID/SHA-1 of directory] For example: 例如:

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, 14032aabd85b43a058cfc7025dd4fa9dd325ea97 is the ID/SHA-1 of the directory that I wanted to explore. 在上面的示例中, 14032aabd85b43a058cfc7025dd4fa9dd325ea97是我想要浏览的目录的ID / SHA-1。 In this case, the result was that four files within that directory were being tracked by my Git repo. 在这种情况下,结果是我的Git仓库正在跟踪该目录中的四个文件。 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. 您可以使用git add <file>...当然。


#4楼

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正在跟踪的所有已提交文件。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值