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
Advertisements
This entry was posted in bash, Git, Scripting, Source Control and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s