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

4

294

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?

Odeen answered 9/5, 2012 at 12:34 Comment(0)
P
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.

Pitts answered 9/5, 2012 at 12:45 Comment(6)
thank you! how can I track that the permission changes were submitted to github?Odeen
You can see it when you view a file (for example, on Rails gitignore file, you will find 100644 as the file permission)Pitts
Making permissions changes on Windows with git (actually changing the file permissions and committing): blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.htmlSwafford
This answer is wrong! Git only tracks if a file is executable or not. It does not track other file permission like writable or readable. Read https://mcmap.net/q/11747/-git-is-changing-my-file-39-s-permissions-when-i-push-to-server for more.Dandiprat
For me webstorm did not catch the change , but in git status, I see changes..Renin
Is there a way to do this globally? git config --global didn't seem to work.Latchkey
W
362

@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
Waistcloth answered 12/1, 2014 at 4:39 Comment(3)
It should be noted that you actually have to use '-x/+x'. You can not set any other permissions or a bitmask.Phosphorate
note using git commit -a didn't do anything for me, however setting message on the command line did. Bit of a quirkSanctimony
The command order should be : # git update-index --chmod=+x script.sh # git ls-tree HEAD # git commit -m "Changing file permissions" # git pushAlexia
P
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.

Pitts answered 9/5, 2012 at 12:45 Comment(6)
thank you! how can I track that the permission changes were submitted to github?Odeen
You can see it when you view a file (for example, on Rails gitignore file, you will find 100644 as the file permission)Pitts
Making permissions changes on Windows with git (actually changing the file permissions and committing): blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.htmlSwafford
This answer is wrong! Git only tracks if a file is executable or not. It does not track other file permission like writable or readable. Read https://mcmap.net/q/11747/-git-is-changing-my-file-39-s-permissions-when-i-push-to-server for more.Dandiprat
For me webstorm did not catch the change , but in git status, I see changes..Renin
Is there a way to do this globally? git config --global didn't seem to work.Latchkey
L
1

Simply run git update-index

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

Lanell answered 14/12, 2023 at 9:15 Comment(0)
S
0

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

Sobranje answered 5/2, 2023 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.