gcbenison
gcbenison

Reputation: 11963

Find the commit that changed file permissions

What combination of arguments to git log or similar will find the commit that changed permissions on a file?

I can use git log -p <file> and grep for "new mode", but that doesn't seem very satisfying.

Upvotes: 4

Views: 1190

Answers (3)

Sungam
Sungam

Reputation: 1734

My solution use git log --summary and grep

List all commits that the permission of a given file is modified

git log --summary {file} |grep -e ^commit -e"=>"|grep '=>' -B1 | grep ^commit

If {file} is omitted, it will list all commits, where any file's permission is modified.

Upvotes: 7

jthill
jthill

Reputation: 60497

Git doesn't store file permissions. It checks files out with (umask-mediated) 777 for executable files and directories and 666 for ordinary files as demonstrated here (the ls output is truncated of course)

$ git checkout empty
$ umask 0
$ git clean -dfx
$ git checkout master
$ ls -l
-rw-rw-rw-  1 jthill jthill   4012 May 13 13:30 tag.c
drwxrwxrwx  2 jthill jthill   4096 May 13 13:30 builtin
-rwxrwxrwx  1 jthill jthill  22332 May 13 13:30 git-am.sh
lrwxrwxrwx  1 jthill jthill     32 May 13 13:30 RelNotes -> Documentation/RelNotes/1.8.2.txt

Upvotes: 0

twalberg
twalberg

Reputation: 62479

I don't think there is an option that will directly result in a "changed permissions on file" sort of message, but you can use git log --raw -- file.sh and look at the first two columns of the entries for that file, which are the old mode and the new mode. A simple awk script could be used to compare the two...

Upvotes: 2

Related Questions