简体   繁体   English

使用Windows程序保存文件使Cygwin中的Git跟踪文件模式更改

[英]Saving files with Windows programs makes Git in Cygwin track filemode changes

I am currently developing with Cygwin, Git in Cygwin and a Windows editor under Windows. 我目前正在使用Cygwin,Cygwin中的Git和Windows下的Windows编辑器进行开发。 It is quite annoying that saving files from native Windows programs makes a file executable in Cygwin. 从本机Windows程序保存文件使文件在Cygwin中可执行,这很令人讨厌。 I want to track filemodes as we have Unix executables but updating files from Windows just shoudn't change the existing mode. 我想跟踪文件模式,因为我们有Unix可执行文件,但是从Windows更新文件只是不应该更改现有模式。 I'd accept setting filemode once in Cygwin before committing the file the first time. 在第一次提交文件之前,我将在Cygwin中接受一次设置filemode的操作。

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. 我阅读了https://cygwin.com/cygwin-ug-net/using-filemodes.html,但我使用的是NTFS,但我不知道ACL如何影响文件权限。 After all adding noacl to /etc/fstab didn't stop ls -l showing files as executable after updating them from Windows. 毕竟,将noacl添加到/etc/fstab并没有停止ls -l从Windows更新文件后将它们显示为可执行文件。

These two approaches seem to be possible: 这两种方法似乎是可行的:

  1. Make Cygwin keep the original x bit on existing files even after updated from Windows. 使Cygwin即使在Windows中更新后,也保留现有文件上的原始x位。

  2. Configure Git to ignore filemode changes only for already existing files. 将Git配置为仅对现有文件忽略文件模式更改 I really want to save the x flag when I add Unix executable files which is why git config core.fileMode false is not a solution . 我真的想在添加Unix可执行文件时保存x标志,这就是为什么git config core.fileMode false 不是解决方案的原因 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 the x bit information at all and considering it a solution) (很抱歉,但是在进行研究时,我从人们那里读了太多文章,高兴地放弃了所有x位信息,并认为这是一个解决方案)

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. 更新:由于我开始使用Komodo Edit而不是Geany文件,因此不再使用x位。 Obviously there is some difference between different Windows programs saving files. 显然,不同的Windows程序保存文件之间存在一些差异。 This pretty much solves the problem for me although I think there must be a solution for Geany, too. 尽管我认为Geany也必须有解决方案,但这对我来说几乎可以解决问题。

I see 2 situations here 我在这里看到2种情况

  1. changed locally to +x , ignore change 本地更改为+x ,忽略更改
  2. changed locally to +x , commit change 本地更改为+x ,提交更改

To do 1, I have this code in ~/.bashrc . 做1,我在~/.bashrc有这段代码。 ~/.bash_profile should work too ~/.bash_profile应该工作

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 然后要做2,我有一个脚本可以做到这一点

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? git忽略gitconfig?

How do I make git accept mode changes without accepting all text changes? 如何在不接受所有文本更改的情况下使git接受模式更改?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM