Git - 仅添加具有更改文件权限的文件

时间:2017-11-02 10:29:51

标签: git file-permissions git-add

我有很多文件只有文件权限不同。但实际上有些文件被修改了。

我想将只有文件权限更改的所有文件添加到自己的提交中。

git --version

git version 1.8.3.1

git diff输出:

diff --git a/.htaccess b/.htaccess
old mode 100755
new mode 100644
diff --git a/.htaccess.sample b/.htaccess.sample
old mode 100755
new mode 100644
etc...

git diff --name-status

M       .htaccess
M       .htaccess.sample
M       robots.txt
M       index.php
etc...

获取所有已更改的文件

git diff -G. --name-status

输出:

M       robots.txt
M       index.php

但是如何仅添加具有更改权限的文件,以便可以提交这些文件?

编辑:

git diff-files

100755 100644 fd0fa6002522f4f4bc46e4339671a6ea99969371 0000000000000000000000000000000000000000 M      .htaccess
:100755 100644 383313a383445374f63364cd1985753e86418d04 0000000000000000000000000000000000000000 M      .htaccess.sample
:100644 100644 e09ab6b6b0cf13a895d00ec97dae12d8ba2c364b 0000000000000000000000000000000000000000 M      robots.txt
:100755 100644 56bdb6c86654bdba26b750d36db17b5e15279c86 0000000000000000000000000000000000000000 M      index.php
etc...

git diff-files输出看起来像我可以使用的东西。我有什么... ...

# Get all files that have changed content (save to ../found.list file)
$ git diff -G. --name-status | cut -d$'\t' -f 2 > ../found.list

# Get the diff-files that not have changed content
# This list holds all files that have changed permissions, but have no changed content
# so these are the files that need to be committed
$ git diff-files | cut -d$'\t' -f 2 | grep -Fxvf ../found.list

# Check if it worked
$ git diff-files | cut -d$'\t' -f 2 | wc -l
14951
$ git diff-files | cut -d$'\t' -f 2 | grep -Fxvf ../found.list | wc -l
14935
$ git diff -G. --name-status | wc -l
16

此命令似乎有效。但我认为有更简单的方法可以做到。

git diff-files | cut -d$'\t' -f 2 | grep -Fxvf ../found.list | while read x; do git add $x; done

0 个答案:

没有答案