问题
I am currently developing with Cygwin, Git in Cygwin and a Windows editor under Windows. It is quite annoying that saving files from native Windows programs makes a file executable in Cygwin. I want to track filemodes as we have Unix executables but updating files from Windows just shoudn't change the existing mode. I'd accept setting filemode once in Cygwin before committing the file the first time.
I read https://cygwin.com/cygwin-ug-net/using-filemodes.html but I'm on NTFS and I don't know how the ACLs will affect the file permissions. After all adding noacl
to /etc/fstab
didn't stop ls -l
showing files as executable after updating them from Windows.
These two approaches seem to be possible:
Make Cygwin keep the original
x
bit on existing files even after updated from Windows.Configure Git to ignore filemode changes only for already existing files. I really want to save the
x
flag when I add Unix executable files which is whygit config core.fileMode false
is not a solution. This saves all files as non-executable. (Sorry for all the emphasizing but while doing research I read too many articles from people happily dropping all thex
bit information at all and considering it a solution)
What is a solution to either approach? I'd actually prefer the 1st one as it feels cleaner.
Update: Since I started using Komodo Edit rather than Geany files don't get the x
bit anymore. Obviously there is some difference between different Windows programs saving files. This pretty much solves the problem for me although I think there must be a solution for Geany, too.
回答1:
I see 2 situations here
- changed locally to
+x
, ignore change - changed locally to
+x
, commit change
To do 1, I have this code in ~/.bashrc
. ~/.bash_profile
should work too
PROMPT_COMMAND='
if [ -d .git ]
then
if [ ! -g .git/config ]
then
git config core.filemode 0
chmod +s .git/config
fi
fi
'
Then to do 2, I have a script that does this
git update-index --skip-worktree --chmod=+x hello-world.sh
git update-index --no-skip-worktree hello-world.sh
Run like this
git chmod.sh hello-world.sh
.bashrc
git-chmod.sh
Git ignoring gitconfig?
How do I make git accept mode changes without accepting all text changes?
来源:https://stackoverflow.com/questions/26906254/saving-files-with-windows-programs-makes-git-in-cygwin-track-filemode-changes