I have a lot of files where only the file permissions are different. But some files are actually modified.
I would like to add all files where only the file permissions are changed into its own commit.
git --version
git version 1.8.3.1
git diff
output:
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 files that have changed
git diff -G. --name-status
Output:
M robots.txt
M index.php
But how to add only the files with changed permissions, so these can be committed?
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 git diff-files output look like something I could work with. What I have atm...
# 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 seems to work. But I think there will be simpler ways to do it.
git diff-files | cut -d$'\t' -f 2 | grep -Fxvf ../found.list | while read x; do git add $x; done
git status --porcelain=n
— please see the manual page on that command. Basically, it's able to generate a machine-parsable output, from which you could grep out only the bits interesting to you.git status --porcelain
just returns the list of files. How can I get all files with only changed file permissions?$ chmod +x Makefile
then$ git status --porcelain=2
shows1 .M N... 100644 100644 100755 76f853af52c9ed30dc420893155b5297123a2ae1 76f853af52c9ed30dc420893155b5297123a2ae1 Makefile
which lists the changed file access modes.git status --porcelain=2
returnsoption porcelain takes no value
. Probably because its an older git version. (git version 1.8.3.1
)git diff-files
works for you.