How to Chmod 0777 a File and Commit as Is to Git on Windows

How to chmod 0777 a file and commit as is to Git on Windows?

If you want to mark the file as executable, you can use

git update-index --chmod=+x <your_file>

If you really want to have the file writable for everyone, you would have to set up a post-update hook on the linux system, because git does not track file permissions, only the executable bit.

How can just set write permission (unix chmod 0777) to a folder and git commit it in windows?

You cannot. Git does not store the complete permissions for files, it only stores whether a file is executable or not. For folders, it stores no permissions at all.

Your umask will influence the permissions that are used when folders are created on your local machine, but this is not something that can be committed to the repository.

looking for ideas to make sure file permissions are set to chmod 777 in a git repository

yes you can do it .

For example following command adds user execute permission to an arbitrary file:

git update-index --chmod=+x <file>

check this link
Git file permissions on Windows

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

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.

Git file permissions on Windows

I found the solution of how to change permissions (also) on Windows here: http://blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.html

For example following command adds user execute permission to an arbitrary file:

git update-index --chmod=+x <file>

How do I make Git ignore file mode (chmod) changes?

Try:

git config core.fileMode false

From git-config(1):

core.fileMode
Tells Git if the executable bit of files in the working tree
is to be honored.

Some filesystems lose the executable bit when a file that is
marked as executable is checked out, or checks out a
non-executable file with executable bit on. git-clone(1)
or git-init(1) probe the filesystem to see if it handles the
executable bit correctly and this variable is automatically
set as necessary.

A repository, however, may be on a filesystem that handles
the filemode correctly, and this variable is set to true when
created, but later may be made accessible from another
environment that loses the filemode (e.g. exporting ext4
via CIFS mount, visiting a Cygwin created repository with Git
for Windows or Eclipse). In such a case it may be necessary
to set this variable to false. See git-update-index(1).

The default is true (when core.filemode is not specified
in the config file).

The -c flag can be used to set this option for one-off commands:

git -c core.fileMode=false diff

Typing the -c core.fileMode=false can be bothersome and so you can set this flag for all git repos or just for one git repo:

# this will set your the flag for your user for all git repos (modifies `$HOME/.gitconfig`)
# WARNING: this will be override by local config, fileMode value is automatically selected with latest version of git.
# This mean that if git detect your current filesystem is compatible it will set local core.fileMode to true when you clone or init a repository.
# Tool like cygwin emulation will be detected as compatible and so your local setting WILL BE SET to true no matter what you set in global setting.
git config --global core.fileMode false

# this will set the flag for one git repo (modifies `$current_git_repo/.git/config`)
git config core.fileMode false

Additionally, git clone and git init explicitly set core.fileMode to true in the repo config as discussed in Git global core.fileMode false overridden locally on clone

Warning

core.fileMode is not the best practice and should be used carefully. This setting only covers the executable bit of mode and never the read/write bits. In many cases you think you need this setting because you did something like chmod -R 777, making all your files executable. But in most projects most files don't need and should not be executable for security reasons.

The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:

find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write

If you do that, you'll never need to use core.fileMode, except in very rare environment.

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

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.

Creating a file that becomes executable chmod 777 gihook file

You have a typo in your Ruby code. In general, Unix file modes are specified in octal, which is one of the last cases where people practically use octal in programming. However, you've specified a decimal value here.

As a result, the octal mode you've specified is 1411, which makes your file have no executable permissions for the user, no read permissions for group or other, and the sticky bit set, which is probably not what you wanted.

You can fix this by writing the mode as 0777:

new_file = File.new(file, File::CREAT|File::TRUNC|File::RDWR, 0777)

Note also that it is in general a security problem to write files with mode 777, since any user on the system can modify them. That means that any user who can access the directory in which this hook is written can modify it to execute arbitrary code whenever the hook is run (which, it looks like, is when git commit is run). A more appropriate mode might be 755, which prevents parties other than the user from modifying it.

The documentation for the commit-msg hook is in the githooks manual page. According to the documentation:

It takes a single parameter, the name of the file that holds the proposed commit log message. Exiting with a non-zero status causes the command to abort.



Related Topics



Leave a reply



Submit