gitでファイル一覧を見る方法
コマンドラインで git管理されたファイルをどうやってみるの?
というのを調べて、便利なaliasを作った。
gitkとか、TortoiseGitを使えば良いのだけど、
コマンドラインでさくっと見たいときに便利だし、
加工しやすいしね。
svnでいうと、'svn ls'とか'svn status -v'とかのイメージ。
gitだと、ls-files があるので、試してみる。
ちなみにリポジトリは git のソースコード。
$ git ls-files .gitattributes .gitignore .mailmap COPYING Documentation/.gitattributes Documentation/.gitignore Documentation/CodingGuidelines Documentation/Makefile Documentation/RelNotes/1.5.0.1.txt Documentation/RelNotes/1.5.0.2.txt ...(中略) xdiff/xinclude.h xdiff/xmacros.h xdiff/xmerge.c xdiff/xpatience.c xdiff/xprepare.c xdiff/xprepare.h xdiff/xtypes.h xdiff/xutils.c xdiff/xutils.h zlib.c
とりあえず出てくるのはいいけど、
下位のディレクトリのファイルがわんさかでてきてしまう。
下位のディレクトリはいらないな...
対応するオプションが無いので、自前で加工。
$ git ls-files|perl -pe 's/\/.*/\//'|uniq .gitattributes .gitignore .mailmap COPYING Documentation/ GIT-VERSION-GEN INSTALL Makefile README RelNotes ...(中略) wrap-for-bin.sh wrapper.c write_or_die.c ws.c wt-status.c wt-status.h xdiff-interface.c xdiff-interface.h xdiff/ zlib.c
ls -F 風で満足。こういうのは aliasしとこう!
$ git config --global alias.ls '!'"git ls-files -t|perl -pe 's/\/.*/\//'|uniq -c" $ git config --global alias.ll '!'"git ls-files -cdmokt|perl -pe 's/\/.*/\//'|grep -v '/'" $ git config --global alias.la "ls-files -cdmokt"
ついでにいろいろやってみた。
- git ls : カレントディレクトリのgit管理されたファイル一覧で、 サブディレクトリのファイル数のおまけ付き。
- git ll : ファイルを状態付きで一覧。
- git la : サブディレクト含めて全ファイルを出すとき。
こんだけあればいいだろう~。
ls-filesのオプションの-dmoktは、
- -dmok : カレントディレクトリの全ファイル
- -tが状態を表示する。状態は、
- H : cached
- S : skip-worktree
- M : unmerged
- R : removed/deleted
- C : modified/changed
- K : to be killed
- ? : other
$ touch aaa # added other file
$ git ls |head
1 H .gitattributes
1 H .gitignore
1 H .mailmap
1 H COPYING
374 H Documentation/
1 H GIT-VERSION-GEN
1 H INSTALL
1 H Makefile
1 H README
1 H RelNotes
$ git ll |head
? aaa
H .gitattributes
H .gitignore
H .mailmap
H COPYING
H GIT-VERSION-GEN
H INSTALL
H Makefile
H README
H RelNotes
$ git la |head
? aaa
H .gitattributes
H .gitignore
H .mailmap
H COPYING
H Documentation/.gitattributes
H Documentation/.gitignore
H Documentation/CodingGuidelines
H Documentation/Makefile
H Documentation/RelNotes/1.5.0.1.txt
満足、満足。
おまけ: git本は、Gitメンテナ著作の「入門Git」がオススメ。
| 入門Git (2009/09/19) 濱野 純(Junio C Hamano) 商品詳細を見る Gitメンテナ著作。Gitの使い方だけでなく、オープンソースをソースコード共有という視点での話はなかなか興味深い。 |
あと、たまにはこの手のコマンド一覧をざざっと眺めておくと、
git la とかで出力したテキストの加工をさらっとできて、
にんまりできる。
| 【改訂新版】 Linuxコマンド ポケットリファレンス (Pocket Reference) (2009/04/08) 沓名 亮典、平山 智恵 他 商品詳細を見る |
<関連記事>
- 2012-10-14: Subversionリポジトリのコード変更量を集計する
- 2012-09-26: svnserve をちょっと使ってみる
- 2011-02-17: gitでファイル一覧を見る方法
- 2009-09-26: Pro GitのMarkdownをHTMLで1ファイル化した。pandocは使わない方向で。
- 2009-09-20: git logで、gitk --all くらい情報ほしい
- 2009-09-18: リポジトリはsvn、クライアントはgitを使う
- 2009-03-25: TortoiseSVN 1.6 リリースノートを読んだ
- 2009-03-25: Subversion 1.6.0 Released
- 2008-12-30: Macで Trac+apache の環境構築
- 2008-12-23: Macで Trac+git の環境構築
★☆★コメント★☆★
コメントの投稿
トラックバック
http://iyukki.blog56.fc2.com/tb.php/119-50d59e26
[git]git管理しているファイル一覧を表示する方法。
gitでファイル一覧を見る方法 CodingFirst gitで管理しているファイルってなんだったけかなー?と、思ったら、ls-filesを指定してやればいいのだが、Rails3とかだと、大量にファイルがでてきちゃってて、結局ディレクトリだけわかればいいや。と、いうときに非常に見にくい