What is the fastest way to find out who commited a particular segment of code when using Git?
Asked
Active
Viewed 359 times
2
-
6That would probably be [`git blame`](https://git-scm.com/docs/git-blame) – Cory Kramer Jan 07 '18 at 17:27
-
4Possible duplicate of [What does git blame do?](https://stackoverflow.com/questions/31203001/what-does-git-blame-do) – evolutionxbox Jan 07 '18 at 19:32
-
1Yes, if he knew git blame is what he was looking for in the first place. – harmonica141 Jan 07 '18 at 20:30
1 Answers
2
You can use git blame <filename>
. You will be shown the name of the author, timetag and commit of each code fragment of the file.
This is the syntax you would find on git blame's man page:
usage: git blame [<options>] [<rev-opts>] [<rev>] [--] <file>
<rev-opts> are documented in git-rev-list(1)
--incremental Show blame entries as we find them, incrementally
-b Show blank SHA-1 for boundary commits (Default: off)
--root Do not treat root commits as boundaries (Default: off)
--show-stats Show work cost statistics
--progress Force progress reporting
--score-debug Show output score for blame entries
-f, --show-name Show original filename (Default: auto)
-n, --show-number Show original linenumber (Default: off)
-p, --porcelain Show in a format designed for machine consumption
--line-porcelain Show porcelain format with per-line commit information
-c Use the same output mode as git-annotate (Default: off)
-t Show raw timestamp (Default: off)
-l Show long commit SHA1 (Default: off)
-s Suppress author name and timestamp (Default: off)
-e, --show-email Show author email instead of name (Default: off)
-w Ignore whitespace differences
--indent-heuristic Use an experimental indent-based heuristic to improve diffs
--compaction-heuristic
Use an experimental blank-line-based heuristic to improve diffs
--minimal Spend extra cycles to find better match
-S <file> Use revisions from <file> instead of calling git-rev-list
--contents <file> Use <file>'s contents as the final image
-C[<score>] Find line copies within and across files
-M[<score>] Find line movements within and across files
-L <n,m> Process only line range n,m, counting from 1
--abbrev[=<n>] use <n> digits to display SHA-1s

harmonica141
- 1,389
- 2
- 23
- 27