Reputation: 303
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.
Upvotes: 5
Views: 632
Reputation: 5659
--summary
option of git-log
provides the "mode change" information.
So you can execute git log --follow --summary -- requirements.txt
, and then type /mode
(or /\bmode\b
for regex) to trigger the search for mode
word via the pager means. Use n to navigate to the next occurrence.
It's a better way than the accepted answer, because it doesn't require changing the codebase (the checkouts that git-bisect
does) and should be faster for the same reason.
Moreover, to my knowledge it is the best way, because I invested quite some time into the research, digging through docs, posts and experimenting, and the conclusion is that git has very few search capabilities for permission mode specifically. It can't search them, has no --diff-filter
for them and lacks --format
parameter to only show mode changes. So git-log
with --summary
and some kind of text-search via the output is your best bet.
Upvotes: 0
Reputation: 1787
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
Upvotes: 5
Reputation: 5407
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.
Upvotes: 1