How do I make git accept mode changes without accepting all text changes?

Andrew Grimm picture Andrew Grimm · Oct 23, 2009 · Viewed 28.9k times · Source

I've got the opposite problem from "How do I make Git ignore file mode (chmod) changes?" I've got a file that I've changed executable permission on, but there are also some text changes, and I want to commit the former but not the latter. Is this possible with git?

(Actually, I've made some text changes I want to commit along with the executable permission change, and others I don't want to commit)

Update: Unstaging the text changes to the file, and then doing git add -p again and incorporating some of the text changes managed to get the mode change into staging. (My git version is 1.5.4.3)

Answer

CB Bailey picture CB Bailey · Oct 23, 2009

You should be able to do:

git update-index --chmod=(+|-)x <file>

to adjust the executable bit stored in the index.

You can then commit this separately from any changes to the files content.