Automatically apply “git update-index --chmod=+x” to executable files

后端 未结 6 717
Happy的楠姐
Happy的楠姐 2020-11-29 19:53

I frequently add bash scripts to my git repository, and the scripts have executable permissions in the linux filesystem prior to the git add. But after pushing

6条回答
  •  死守一世寂寞
    2020-11-29 20:18

    A solution without fancy bash scripting:

    1. Set fileMode = true in your .git/config file (or by running git config core.filemode true as others have pointed out)
    2. Change the executable bit on the file's permissions and commit this change. ( chmod u+x $script as you pointed out). You only have to do this once.
    3. Push to the remote

    The next time you pull from there, git will set the committed executable bit on the file. I also had similar problems, this solved them.

    fileMode = true tells git to track the only thing about permissions it can: the executable bit. This means that changes to the executable bit will be recognized by git as changes in the working tree and those changes will be stored in the repo with your next commit.

    Once you committed the desired executable bit you can also reset your fileMode to false so next time git won't bother you with such changes when you don't want to commit them.

提交回复
热议问题