git ls-files

git

書き方

git ls-files [-o|-m|-i] [--exclude-standard]

ディスクではなく索引に入っている経路を並べます。スクリプトで追跡ファイルを回すのに確実な一覧で、-iは単独では使えず-cか-oと--exclude-standardが要ります。

よく使うオプション

オプション意味
-cfiles in the index; the default
-mtracked files modified on disk
-dtracked files that are missing
-ofiles git does not track
-iignored files; must come with -o or -c and --exclude-standard
--exclude-standardapply .gitignore and friends
-sshow mode and object id of each entry
-zseparate paths with NUL for xargs -0

git ls-files

every tracked path, straight from the index

git ls-files -o --exclude-standard

untracked files only, respecting .gitignore

git ls-files -i -c --exclude-standard

tracked 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