Git状态:显示模式(权限)更改

3
当我运行 git status 命令时,许多文件被修改:
$ git status
On branch feature-branch
Your branch is up to date with 'origin/feature-branch'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   file1.txt
    modified:   file2.txt
    modified:   file3.txt
    ...

有没有一种方法可以显示这些文件只更改了它们的权限(模式),而不是它们的内容?我想输出应该像这样:
$ git status
On branch feature-branch
Your branch is up to date with 'origin/feature-branch'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   file1.txt (100644 → 100755)
    modified:   file2.txt (100644 → 100755)
    modified:   file3.txt (100644 → 100755)
    ...

我知道 git diff 会显示像这样的内容:

diff --git file1.txt
old mode 100644
new mode 100755

但我更希望 git status 直接显示这个。


注意:虽然这个问题看起来很相似,但在那种情况下,git status 根本没有检测到模式更改。而在我的情况下,文件被标记为已修改,但我想区分纯文件编辑(修改内容)和只是更改权限的情况。


可能是 git status not showing permission changes 的重复问题。 - Daemon Painter
1
不是的,我已经在问题中添加了一条注释。 - Borek Bernard
1个回答

0

我不相信 Git 会这样做。Git 会为文件更改保留这些状态。

' ' = unmodified
  •   M = modified
  •   A = added
  •   D = deleted
  •   R = renamed
  •   C = copied
  •   U = updated but unmerged

Git 足够聪明,能够告诉我们关于重命名的情况,但它在状态中保持沉默,不会告诉我们关于模式更改的情况。

但您可以编写自己的脚本,解析文件的差异,并查看模式是否已更改,然后更改默认 git status 的输出。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接