Search code examples
git

"git blame" a file access control modifier


I noticed that a couple .txt files in my git repository have execute permissions. I also noticed that when I did chmod a-x *.txt the repo actually showed changes. Here is the output of the git diff after updating the files.

diff --git a/requirements.txt b/requirements.txt
old mode 100755
new mode 100644

Is there a way to blame permissions of a file? (specifically I'd like to find out who added the a+x permissions to these files.


Solution

  • You have probably used git diff command with some commits specified to get the results shown in your question. Let's assume the command was:

    git diff goodcommit..badcommit requirements.txt
    

    In case you omitted ..badcommit part, assume the badcommit is HEAD. You can easily find the offending commit (and a culprit) by running following sequence of commands:

    git bisect start badcommit goodcommit
    git bisect run test ! -x requirements.txt
    

    and wait for finish. At the end you will get a message like:

    running test ! -x requirements.txt
    8088473809f905bd8f3d5825983e8c9fe82b10c6 is the first bad commit
    commit 8088473809f905bd8f3d5825983e8c9fe82b10c6
    Author: author
    Date:   Fri Jun 16 23:05:49 2017 +0100
    
        commit message
    

    To get back to normal work, just run:

    git bisect reset