PositiveGuy
PositiveGuy

Reputation: 20182

Way to List All Changes on a File in Git

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.

Upvotes: 2

Views: 1466

Answers (3)

janos
janos

Reputation: 124646

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

Upvotes: 2

Dale
Dale

Reputation: 1941

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

Upvotes: 1

Davis Herring
Davis Herring

Reputation: 39818

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.

Upvotes: 0

Related Questions