2

I'm trying to track down who removed some code on a particular file. I don't know when it was but certainly within the past month.

Is there a way to list history of code changes and details on a specific file via a git command?

Update

this didn't work

git log -p --follow -- src/app/company/index.js

enter image description here

Update

tried this

git blame src/app/company/index.js fatal: no such path 'src/app/company/index.js' in HEAD

Update

ugh, company is capital C...that's what the problem was.

PositiveGuy
  • 17,621
  • 26
  • 79
  • 138

3 Answers3

2

You can use git log -- path/to/file to see the commits that modified the file.

It's especially convenient together with the -p flag, to include the diff (patch) that affected the file.

If you want to track the history of a file through renames, then also add --follow.

git log -p --follow -- path/to/file
janos
  • 120,954
  • 29
  • 226
  • 236
1

You can, but it might be worth using git blame for this, it shows who made the last edit to each line in the file.

git blame

Useage is like this

git blame examplefile
Dale
  • 1,911
  • 11
  • 18
0

git log accepts file names. If the file doesn’t exist in the current commit, you have to use -- before the name to avoid interpreting it as a revision name.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76