【问题标题】:Why does Git write to my files?为什么 Git 会写入我的文件?
【发布时间】:2017-01-11 04:41:09
【问题描述】:
我在 Git 存储库中有一些源文件,main.c 和其他一些文件。我使用 Vim 来编辑这些文件。
假设我正在编辑main.c。我进行了更改,告诉 Vim 写出,然后切换到终端(不杀死 Vim)并提交/推送。如果我用main.c 回到 Vim 并再次尝试写出,我会收到以下警告:
WARNING: The file has been changed since reading it!!!
Do you really want to write to it (y/n)?
提交/推送如何修改我的源文件?为什么?
【问题讨论】:
标签:
git
vim
git-commit
git-push
【解决方案1】:
这可能是权限问题(git 更改文件的可执行位)。
在git config core.filemode false 之后重试。
解决方法很简单:用:e filename重新打开文件。
或者(如果您的文件已保存并且当前没有修改),运行:bufdo e,这将使 Vim 重新打开每个缓冲区。
【解决方案2】:
你能告诉我们你的 .gitattributes 文件吗?你是在告诉它改变行尾吗?
你为什么不尝试做一个差异并告诉我们有什么不同。
【解决方案3】:
其他答案表明,写入可能是由于 Git 执行了行尾更改,或者扩展了配置的属性。一个简单的解决方案是
:set autoread
在 Vim 中,自动更新文件(只要您没有更改它,根据您的用例,这似乎不太可能)。
'autoread' 'ar' boolean (default off)
When a file has been detected to have been changed outside of Vim and
it has not been changed inside of Vim, automatically read it again.