Alexander Abramovich
Alexander Abramovich

Reputation: 11438

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

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?

Upvotes: 300

Views: 309349

Answers (4)

Amin Shojaei
Amin Shojaei

Reputation: 6508

Simply run git update-index

Then you will see your changes in git status and can commit them.

Upvotes: 1

stefan
stefan

Reputation: 694

As Adam wrote: Git does not track the file mode in its entirety. https://git-scm.com/docs/git-config#Documentation/git-config.txt-corefileMode

Upvotes: 1

Vincent B.
Vincent B.

Reputation: 4196

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.

Upvotes: 265

ewwink
ewwink

Reputation: 19154

@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

Upvotes: 381

Related Questions