【问题标题】:Git status: show mode (permission) changesGit状态:显示模式(权限)更改
【发布时间】:2020-02-07 18:01:59
【问题描述】:

当我运行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 已经向我展示了这个,我会更喜欢。


注意:This question 看起来很相似,但在这种情况下,git status 根本没有检测到模式更改。就我而言,文件被标记为已修改,但我想将纯文件编辑(修改内容)与仅更改权限区分开来。

【问题讨论】:

标签: git


【解决方案1】:

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

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

Git 足够聪明,可以告诉我们有关重命名的信息,但它对模式更改的状态保持不变。

但是你可以自己做一个脚本来解析文件的差异,看看模式是否改变了,然后它会改变默认git status的输出。

【讨论】:

    猜你喜欢
    • 2022-01-21
    • 2015-11-02
    • 2014-04-18
    • 2021-09-12
    • 2016-01-04
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多