Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create file execute mode permissions in Git on Windows?

Tags:

git

I use Git in Windows, and want to push the executable shell script into git repo by one commit.

Usually I need to do two steps (git commit).

$ vi install.sh $ git add install.sh   $ git commit -am "add new file for installation" # first commit [master f2e92da] add support for install.sh  1 files changed, 18 insertions(+), 3 deletions(-)  create mode 100644 install.sh $ git update-index --chmod=+x install.sh $ git commit -am "update file permission"        # second commit [master 317ba0c] update file permission   0 files changed   mode change 100644 => 100755 install.sh 

How can I combine these two steps into one step? git configuration? windows command?

Remind: Two answers are good, git add --chmod=+x file is supported in new git version

Reference: see question in Git file permissions on Windows for second commit

like image 907
Larry Cai Avatar asked Feb 11 '14 01:02

Larry Cai


People also ask

How do I give Git permission to run a file?

The solution is to use the Git update-index command to assign the execute permissions. This will assign execute permissions to the bash file. After that you can commit the changes to the repo.

How do I make a script executable in Git?

git add --chmod=+x -- afile git commit -m"Executable!" That makes the all process quicker, and works even if core. filemode is set to false.

Does Git include file permissions?

Git Tracks ONLY the Executable Bit of the Permissions for the User Who Owns the File.


1 Answers

There's no need to do this in two commits, you can add the file and mark it executable in a single commit:

C:\Temp\TestRepo>touch foo.sh  C:\Temp\TestRepo>git add foo.sh  C:\Temp\TestRepo>git ls-files --stage 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       foo.sh 

As you note, after adding, the mode is 0644 (ie, not executable). However, we can mark it as executable before committing:

C:\Temp\TestRepo>git update-index --chmod=+x foo.sh  C:\Temp\TestRepo>git ls-files --stage 100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       foo.sh 

And now the file is mode 0755 (executable).

C:\Temp\TestRepo>git commit -m"Executable!" [master (root-commit) 1f7a57a] Executable!  1 file changed, 0 insertions(+), 0 deletions(-)  create mode 100755 foo.sh 

And now we have a single commit with a single executable file.

like image 164
Edward Thomson Avatar answered Sep 20 '22 21:09

Edward Thomson