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