Skip to content

Updating and committing only a file's permissions using git version control

295

Just turned an some.sh file into an executable (chmod 755 ...), the permissions were updated but not the content. Is there a way to commit the file into git, so that the executable bit will be restored/set on clone / checkout / pull ?

Update: how can I track that the new permissions were submitted to github?

git Share Follow edited Sep 27, 2018 at 2:19 Cœur's user avatar Cœur 37.9k2525 gold badges200200 silver badges273273 bronze badges asked May 9, 2012 at 12:34 Alexander Abramovich's user avatar Alexander Abramovich 11.3k2626 gold badges7272 silver badges111111 bronze badges Add a comment 4 Answers Sorted by:

Highest score (default) 363

@fooMonster article worked for me

git ls-tree HEAD

100644 blob 55c0287d4ef21f15b97eb1f107451b88b479bffe script.sh As you can see the file has 644 permission (ignoring the 100). We would like to change it to 755:

git update-index --chmod=+x script.sh

commit the changes

git commit -m "Changing file permissions"

[master 77b171e] Changing file permissions 0 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 script.sh Share Follow edited Jul 29, 2017 at 14:26 answered Jan 12, 2014 at 4:39 ewwink's user avatar ewwink 18.8k22 gold badges4545 silver badges5555 bronze badges 19 It should be noted that you actually have to use '-x/+x'. You can not set any other permissions or a bitmask. – Devolus Sep 21, 2018 at 11:50 2 note using git commit -a didn't do anything for me, however setting message on the command line did. Bit of a quirk – JonnyRaa Dec 24, 2018 at 11:39 4 The command order should be : # git update-index --chmod=+x script.sh # git ls-tree HEAD # git commit -m "Changing file permissions" # git push – SimonDepelchin Sep 9, 2019 at 7:18 Add a comment 259

By default, git will update execute file permissions if you change them. It will not change or track any other permissions.

If you don't see any changes when modifying execute permission, you probably have a configuration in git which ignore file mode.

Look into your project, in the .git folder for the config file and you should see something like this:

[core] filemode = false You can either change it to true in your favorite text editor, or run:

git config core.filemode true Then, you should be able to commit normally your files. It will only commit the permission changes.