git ls-files
git
用法
git ls-files [-o|-m|-i] [--exclude-standard]列出索引里的路径而不是磁盘上的文件,所以脚本遍历已跟踪文件时靠它最稳;-i 不能单独用,必须配 -c 或 -o 再加 --exclude-standard。
常用选项
| 选项 | 含义 |
|---|---|
| -c | files in the index; the default |
| -m | tracked files modified on disk |
| -d | tracked files that are missing |
| -o | files git does not track |
| -i | ignored files; must come with -o or -c and --exclude-standard |
| --exclude-standard | apply .gitignore and friends |
| -s | show mode and object id of each entry |
| -z | separate paths with NUL for xargs -0 |
示例
git ls-filesevery tracked path, straight from the index
git ls-files -o --exclude-standarduntracked files only, respecting .gitignore
git ls-files -i -c --exclude-standardtracked files that .gitignore says should be ignored
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git ls-files 是做什么的?
列出索引里的路径而不是磁盘上的文件,所以脚本遍历已跟踪文件时靠它最稳;-i 不能单独用,必须配 -c 或 -o 再加 --exclude-standard。
Q. 怎么写?
git ls-files [-o|-m|-i] [--exclude-standard] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 8 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-ls-files