4

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.

Ryan Baker
  • 193
  • 7
  • `git blame` does not look at permissions, only contents. Use [ArturFH's method](https://stackoverflow.com/a/44598709/1256452), since that lets you run arbitrary tests. – torek Jun 16 '17 at 22:44

2 Answers2

5

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
ArturFH
  • 1,697
  • 15
  • 28
1

Git only stores the file contents, and execute bit value. See this answer for further info. So it will not reflect any other permission changes.

You can use:

git log --follow -p -- a/requirements.txt

to view the history of a file.

Peter Reid
  • 5,139
  • 2
  • 37
  • 33
  • 1
    Because my question asks specifically about the execute bit, it seems like your answer kind of misses the mark of what I was asking. Thanks for your help, though! – Ryan Baker Jun 16 '17 at 21:38
  • So you don't care about any other permission bits? – Peter Reid Jun 16 '17 at 22:23
  • 2
    Right, just like I said in the question > 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. – Ryan Baker Jun 17 '17 at 16:11