If I have a file in a git repository, how can I determine whether a given revision of the file is executable or not?
I know that git keeps track of whether files are executable or not, and git show
will show changes in execute permissions. For example, the output of git show
on a given revision might include:
diff --git file file
old mode 100644
new mode 100755
which indicates that the file acquired execute permission.
I want to determine whether the current revision, or any specified revision, of a specified file has execute permission.
(Background: I have a wrapper script that extracts a specified version of a file using
git show $commit:./$filename > ./$filename.$commit
I want to run chmod +x
on the new file if and only if that version of the file executable in the repository.)
Use git ls-tree
, passing in the ref and file path you want to inspect.
For example, git ls-tree HEAD foo.txt
will give something like
100644 blob 3e1d68d0714fd3d46ec22a685e317f0cf47f5e83 foo.txt
The 644 in the first column indicates a non-executable file. 755 would indicate an executable file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With