Home > Software engineering >  Easiest way to find when a specific change occured in git
Easiest way to find when a specific change occured in git

Time:02-19

Let's say I have a file, say foo.py. Browsing the code, some changed occured and I would need to know when that specific change was made. For instance:

def bar():
   answer = 43
   return f"The answer is:{answer}"

The answer obviously being 42, and there not having a comment, I need to find out when in the commit history that line was changed to understand if it is legit or not.

Any good, programmatic way to do this? Or is just browsing the commit history the way to do it?

CodePudding user response:

You can use git annotate:

https://git-scm.com/docs/git-annotate

so

git annotate -L <line number start, line number end> <file>

or specifically

git annotate -L 4,-2 foo.py

or even

git annotate foo.py

Also there are tons of tools depending on your IDE that will do this without running to the command line. Git lens is one of many for VSCode: .

  •  Tags:  
  • git
  • Related