37

I've got the opposite problem from "How do I make git ignore mode changes (chmod)?" 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)

halfer
  • 19,824
  • 17
  • 99
  • 186
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

3 Answers3

82

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.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
15

git add -i will let you selectively add some hunks from a file to the index. I don't know whether or not it's sensitive to permissions, but if you were to add a hunk after the chmod operation, it might end up in the index correctly even without explicitly updating the permission.

Bob Aman
  • 32,839
  • 9
  • 71
  • 95
  • 4
    That's correct, git add -i (and git add --patch) ask you "Stage mode change?" right before they ask about the changed hunks. – Phil Oct 23 '09 at 03:25
  • Thanks Phil. That ability seems to be associated with git 1.5.6 according to the release notes. (Unfortunately, my git isn't that recent) – Andrew Grimm Oct 23 '09 at 04:00
3

Charles’ answer was adding both file mode and content changes to the index for me. I worked around it like this.

git update-index --skip-worktree --chmod=+x <file>
git update-index --no-skip-worktree <file>

Example

Alternatively you can do

git update-index --chmod=+x <file>
git config interactive.singlekey 1
echo na | git reset -p
Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407