Git - add files with changed file permissions only

I have a lot of files where only file permissions are different. But some files are actually modified.

I would like to add all files in which only file permissions will be changed in its own commit.

git --version

git version 1.8.3.1

git diff conclusion:

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...

Get all modified files

git diff -G. --name-status

Conclusion:

M       robots.txt
M       index.php

But how to add only files with changed permissions so that they can be fixed?

Edit:

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...

The output files of git diff-files look the way I could work. What I have...

# 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

This command is working. But I think there will be simpler ways to do this.

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

Source: https://habr.com/ru/post/1688585/


All Articles