How to remove execute bit from files in Git

Occasionally, files get committed to source control having the wrong file permissions. Either they don’t have execute when they should, or they have execute when they shouldn’t, just for example. I came across this a couple of weeks ago and came up with the following solution. It changes the file permissions recursively on files and also does the same to the Git index. Please refer to the Git documentation for config.fileMode for more information on why this might happen.

asoftwareguy@Intrepid:~/Projects/a$ find -executable -type f -exec git update-index --chmod=-x {} \;
asoftwareguy@Intrepid:~/Projects/a$ find -executable -type f -exec chmod -x {} \;
asoftwareguy@Intrepid:~/Projects/a$ git status
asoftwareguy@Intrepid:~/Projects/a$ git commit -m "Changing file permissions to remove execute bit"
asoftwareguy@Intrepid:~/Projects/a$ git push
Posted in bash, Git, Scripting, Source Control | Tagged , , , , , , | Leave a comment