You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何判断Git仓库中指定版本的文件是否具备可执行权限?

How to Check if a Specific Version of a File in Git Has Executable Permissions

Great question! Git absolutely tracks the executable permission status of files, and there are a couple of straightforward ways to verify this for any commit (including the current HEAD):

1. Use git ls-tree to directly inspect the file mode

This is the most direct method to check the permission mode of a file at a specific commit. Git stores file permissions in a "mode" field, where:

  • 100755 means the file is executable (read/write/execute for owner, read/execute for group and others)
  • 100644 means it's a regular non-executable file (read/write for owner, read-only for group and others)

Run this command, replacing <commit-hash> with your target commit (or HEAD for the current version) and <file-path> with the path to your file:

git ls-tree <commit-hash> -- <file-path>

Example Output:

100755 blob a1b2c3d    scripts/deploy.sh

The first field (100755) tells you the file has executable permissions in that commit. If it showed 100644, the file wouldn't be executable.

2. Use git cat-file to view blob details

If you want more granular details about the file's blob object, you can use git cat-file with the -p (pretty-print) flag. First, get the blob hash from git ls-tree, then run:

git cat-file -p <blob-hash>

The first line of output will show the mode, like:

mode 100755
blob a1b2c3d...

3. Check permission changes with git show

As you mentioned, git show can display permission changes between commits. If you want to see when the executable permission was added or removed, run:

git show <commit-hash> -- <file-path>

Look for lines like:

diff --git a/scripts/deploy.sh b/scripts/deploy.sh
old mode 100644
new mode 100755

This tells you that the commit in question changed the file from non-executable to executable.

Note for the current working directory

If you just want to check the local file's permissions (not the version stored in Git), you can use your system's ls -l command:

ls -l <file-path>

But keep in mind: local permissions might differ from what's in Git if you modified them without committing the change. Always use git ls-tree HEAD -- <file-path> to confirm the version tracked in the current commit.

内容的提问来源于stack exchange,提问作者Keith Thompson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:32:03