0

My change got dropped in one of the files in a Git develop branch. I used the below command to check on which commit in the develop branch the changes got dropped:

git log -p <filename> 

But the output is not showing clearly which commit to develop has broken it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Akash Chavan
  • 325
  • 2
  • 7
  • 22
  • Look into using git bisect. You have to do the work of figuring out which commit was responsible. All the more reason to always use meaningful commit messages. – Tim Biegeleisen Mar 15 '18 at 09:24
  • Possible canonical question: *[View the change history of a file using Git versioning](https://stackoverflow.com/questions/278192/)* – Peter Mortensen Sep 17 '21 at 20:04

1 Answers1

1

Two points to consider:

  • Git does not track file renames: it does not record them to the commit history, so a rename appears in a commit as a removal of the file with the old name and addition of the file with the new name.

    So if your file got renamed, you have to exercise Git's ability to detect renames/copies at the history traversal (that's what git log does in the first place). Look at the -M and -C command-line options of git log for more information.

  • There exists lesser-known features of git log which are of immense power: the -S, -G and -L options. (Also see the accompanying --pickaxe-all and --pickaxe-regex options.)

    These features allow for searching the history for the appearances or disappearances of particular bits of code, and more.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kostix
  • 51,517
  • 14
  • 93
  • 176
  • …and in the case I failed to actually parse your question, you might just add `--pretty=full` to your `git log` invocation. – kostix Mar 15 '18 at 11:00