Search code examples
gitgit-blame

Git blame for deleted section


I need to know who and when deleted some portion of a source file using git. Unfortunately, it seems git blame won't directly show me that, as said section is totally absent from file in the current revision. Any suggestions ?


Solution

  • You can find commits which were changing something in lines having certain string. This way you can see which commit deleted some line if you know what its content was

    git log -S <string> path/to/file
    

    In order to find how exactly these lines were written you can see your file in some very old commit:

    git show old-commit-hash^:src/path/to/file