Find Out Author Of A Line With Git Log Or Git Blame


The concern is documenting the ways to find who is behind a particular change with git — not file history, but (as I call it) the line history.

1. git log -S

  • one way of going about that
  • you need a string or a piece of code
  • you search the entire repo
git log -S "_STRING_" --pretty=format:"%C(auto)%h%d%Creset %C(cyan)(%ci)%Creset %C(green)%cn <%ce>%Creset" --name-status --date=short
git log -S "nomad" --pretty=format:"%C(auto)%h%d%Creset %C(cyan)(%ci)%Creset %C(green)%cn <%ce>%Creset" --name-status --date=short

2. git blame

  • get the exact location within the file (exact line, or range, or the whole file if short)
  • search within a single file
  • you need a line number + filename
  • run git blame with L parameter to see who has modified that line exactly
git blame -e -L _LINE_N_START_, _LINE_N_END_ _FILENAME_
git blame -e -L 9,9 C:\Users\Admin\Documents\workspace\work.log\kb\powershell\pub-wlog.ps1

3. sources

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store