1

I have an executable file in a git repository.

How do I find out which commit made that file executable?

I tried git log file.txt but that does not show changes in file modes and searching man pages and google was fruitless.

Prvaak
  • 757
  • 1
  • 6
  • 13

3 Answers3

1

Use:

git log -p file.txt | grep --before-context 7 "old mode"

(If your commit text is multiple lines long, increase the before context line option so it includes the commit ID)

The file mode change include "old mode" and "new mode" in the log, which is how this works.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
  • Thank you! This is exactly what I have been looking for. It's a personal pet peeve of mine when someone accidently makes something executable. – donatJ Jun 01 '16 at 21:23
1

git log --raw (or git whatchanged, which skips merges as well) extracts the modes:

:100644 100644 bcd1234... 0123456... M file0

The first octal number is the old mode, the second is the new. If the file became executable the old mode will end with 644 and the new one with 755. A regular file has mode 100 before the 644 or 755. So this will find it quickly:

git log --raw -- path/to/file | grep -B 1 '^:100644 100755 '

If there are multiple transitions from non-executable to executable, this will find all of them.

torek
  • 448,244
  • 59
  • 642
  • 775
0

Try using git bisect How to use git bisect?

It can help you search by picking commits in the most optimal way. You will start by picking two commits, one where it doesn't work and one where it does. After that git will give you a commit, you test if it works and respond accordingly. After a few tries you will find the right commit.

Community
  • 1
  • 1
softarn
  • 5,327
  • 3
  • 40
  • 54