3

I have modified a file, and I do not know anymore when. I want to see all the commits where I have changed that file. And based on those commits I want to search for other modifications in other files that are linked to the modification I am searching for. I have tried git blame but it seems that is just showing the last commit and uncommitted changes. Can anyone tell me how to do this?


To be more explicit: I am searching modifications in a json file and based on those, I have done some modification in my application code (cpp) files. So I want to search those commits and see the code that I have modified. P.S.: I have changed the structure of the json meanwhile, so I do not want just the last modification.

sop
  • 3,445
  • 8
  • 41
  • 84
  • `git log --follow -p file` – AgileDan Oct 30 '14 at 15:11
  • 1
    possible duplicate of [View the change history of a file using Git versioning](http://stackoverflow.com/questions/278192/view-the-change-history-of-a-file-using-git-versioning) – Dettorer Oct 30 '14 at 15:11

4 Answers4

6

To view what and how commits changed some file you can use log command with -p switch:

git log -p somefile/somefile.cpp
rufanov
  • 3,266
  • 1
  • 23
  • 41
1

You can see all the commits that affect a certain file with:

git log -- <filename>

If you want to see the other files that were modified along with that file, you can use the --name-only option. This will list all the files that are modified in that commit.

git log --name-only <filename>
Schleis
  • 41,516
  • 7
  • 68
  • 87
0

To find out who changed a file, you can run git blame against a single file, and you get a breakdown of the file, line-by-line, with the change that last affected that line. It also prints out the timestamp and author information as well link

gpullen
  • 1,093
  • 2
  • 14
  • 28
0

In everyday work i find this the most convenient:

gitk <some file or directory>

It's nice to be able to quickly filter out all commits that changed the content of a certain directory, especially in a larger system. The fact that you can click the files to see the diffs instantly makes it, at least for, the fastest way to get an overview.

Martin G
  • 17,357
  • 9
  • 82
  • 98