2

I have an interesting situation debugging a critical function of my platform, and came across this line in a relevant function in the codebase:

// This line below is where shit is hitting the fan

It would be extremely helpful to see on what commit that line of code was submitted to the Github, it could have been from a previous developer on the codebase working on the same issue I'm seeing. It would be incredibly helpful to see what else they had been working on during that commit and the ones around it.

I know I could go to that particular file, search all commits ever that updated that file and search those commit by commit, but that would take ages.

Is there an efficient way using Git / Github to find out when a line of code was first committed?

Zach Cook
  • 604
  • 12
  • 33
  • 8
    Use the blame function, either locally with `git blame` or hit the Blame button when viewing the file on github. Note that for each line or section you will see the last commit that changed that part. – Lasse V. Karlsen Jul 28 '19 at 21:15
  • @LasseVågsætherKarlsen Thank you!! I honestly prefer this as the answer over the one VonC provided. Was super straight to the point. Even though they're both right. Could you put this as an answer so I can check mark it? – Zach Cook Aug 22 '19 at 02:35
  • No, I will not, if you think there's something wrong or missing with VonC's answer, you should make a comment on his answer instead as I would essentially be repeating his answer, and that's not useful or constructive. – Lasse V. Karlsen Aug 22 '19 at 06:47
  • Ok sorry. VonC updated his answer so problem solved – Zach Cook Aug 25 '19 at 17:29

1 Answers1

8

GitHub is the most convenient, if that line is in a public repository stored on GitHub, with the "Blame" button:

https://stackoverflow.com/a/37625238/6309
(Source: "git-blame for pull requests")

As I describe in "How do I navigate to the earliest commit in a Github repository?", the improved blame view allows you to find:

  • who last published a commit with that line
  • (more importantly), who committed that line before that last commit: that allows you to go back to the first commit with that line.

But you can achieve the same result in a local clone with a pickaxe search (that I described in 2010):

git log -S"shit is hitting"

That last entry produced by that command will be the first commit where that string was introduced.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @ZachCook OK. Lede restored (I forgot it was spelled/spelt "lede": https://www.merriam-webster.com/words-at-play/bury-the-lede-versus-lead) – VonC Aug 22 '19 at 06:16