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.
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.
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.
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.