首页 > 解决方案 > 拉取请求表明每个文件都已更改,但每个文件都没有更改

问题描述

我的拉取请求表明我有 7188 个更改的文件,几乎所有这些都没有实际更改。我的实际更改是大约 10 个文件。

我是怎么进入这个奇怪的 git 状态的,我又是怎么出去的?

在此处输入图像描述

标签: gitgithubpull-request

解决方案


你有没有设置类似autoctrl的东西?如果是这种情况,您可能已经更改了所有这些文件的 EOL 格式。我一定要写一篇关于这个的博客文章告诉人们不要使用它......永远......永远!!!!使用 .gitattributes 告诉 git 不要搞乱 EOL 格式:

* -text

那应该这样做....为了更正你搞砸的这个修订:

# first, make sure that you have setup .gitattributes appropriatetly
git checkout HEAD~1 -- . # got the content back of all the files as they where on the previous revision (don't worry you won't lose your work, because you already committed it, right?).
# set up .gitattributes appropriately _again_ because it was probably cleared by the previous command
# now, get the list of files that actually had something meaningful
git status -w
# the files that are listed there are the files that should have been committed before
# check them out and be ready to change their EOL to what it was on the original revision
git checkout HEAD -- file1 file2 file3
# make sure that the eol format is not busted. If you run git diff HEAD~1 you should only see the real changes that you applied, not the whole files getting cleared and then having full content readded
git add .
# now we amend the revision to how it should have been 
git commit --amend --no-edit
# push -force if required

你很高兴。


推荐阅读