Home·Terminal commands

git blame

git

Usage

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

Marks each line with the commit that last changed it; a pure reformat hides the real author, which is what -w and --ignore-rev are for.

Common flags

FlagMeaning
-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

Examples

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

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git blame do?

Marks each line with the commit that last changed it; a pure reformat hides the real author, which is what -w and --ignore-rev are for.

Q. How do I type it?

git blame [-L <start>,<end>] <file> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-blame