git blame

git

書き方

git blame [-L <start>,<end>] <file>

一行ごとに最後に変えたコミットを添えて見せます。整形だけのコミットが本当の作者を隠すので、-wや--ignore-revを使います。

よく使うオプション

オプション意味
-L <a>,<b>only those lines
-wignore whitespace, so re-indenting stops hiding the author
-Cfollow code moved in from another file
--ignore-rev <rev>skip a commit, e.g. a bulk reformat
-eshow email addresses instead of names
-sdrop the author and date columns

git blame -L 40,60 src/app.ts

who last touched lines 40 to 60

git blame -w -C src/app.ts

looks past whitespace and moved code

git blame --ignore-rev 9f3c2ab src/app.ts

ignores the commit that reformatted everything

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git blame は何をしますか。

一行ごとに最後に変えたコミットを添えて見せます。整形だけのコミットが本当の作者を隠すので、-wや--ignore-revを使います。

Q. どう打ちますか。

git blame [-L <start>,<end>] <file> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-blame