git - 在 git diff 中避免“文件末尾没有换行符”
问题描述
我很确定我理解文件末尾没有换行符的含义。我想提供一个我很久以前创建并重新设置的分支的拉取请求(提交可能来自之前.gitattributes
添加的时间)。我看到一些.java
源代码文件只有变化
-}
\ No newline at end of file
+}
无论配置如何,我都希望将这些更改从 PR 提交中排除。我想避免选择更改git difftool
并扩大我对git
.
问题是我已经不明白这种变化是如何存在的,因为有一个.gitattributes
with
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text
*.java text
*.css text
*.js text
*.xml text
*.dtd text
*.xsl text
*.properties text
*.txt text
*.svg text
*.yml text
*.md text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.gif binary
*.jpg binary
*.jpeg binary
*.eot binary
*.ttf binary
*.woff binary
*.woff2 binary
在存储库中,我运行git rm --cached -r . && git add .
了应该将所有行尾转换为 LF 因为*.java text
(也尝试过*.java text
),但是没有显示任何更改(反对HEAD
)并且git diff
仍然显示行尾差异。
也find ./ -type f -name '*.java' -exec dos2unix {} \;
不会导致任何更改被识别git status
并git diff master
仍然显示行结束更改(而工作目录没有暂存或未暂存的更改)。
我对隐藏更改不感兴趣,就像git diff --ignore-all-space
会做的那样。
我git
在 Ubuntu 18.04 上使用 2.17.1。
解决方案
问题:\文件末尾没有换行符
$ git diff
diff --git a/abc.txt b/abc.txt
index 5996e61..6a3c3a9 100644
--- a/abc.txt
+++ b/abc.txt
{
+ **Actual change**
FR(srctxt,reptxt,fname)
else:
- os._exit(1)
\ No newline at end of file
+ os._exit(1)
解决方案: 删除最后一行并使用echo -n "APPEND LAST LINE TEXT AFTER REMOVING THE LAST LINE TEXT" >>abc.txt
$ **echo -n " os._exit(1)" >> abc.txt**
$ **git diff**
diff --git a/abc.txt b/abc.txt
index 5996e61..f2b2e74 100644
--- a/abc.txt
+++ b/abc.txt
@@ -419,6 +419,7 @@ EStatus
{
+ **Actual change**
FR(srctxt,reptxt,fname)
推荐阅读
- facebook - Facebook Graph API - 访问用户照片时如何避免请求限制?
- powerapps - 使用列表中的字段而不在表单上可见的数据卡中使用它
- vba - 如何填充文件的最后保存用户和最后保存日期
- firebase - 管理员用户和身份验证用户 Firebase 数据库的读写权限规则
- javascript - 使用 JavaScript 或 TypeScript 做出反应?
- r - 如何按名称、列索引和同时删除列来对数据框进行子集化
- android - Android Studio 崩溃后出现“无效的符号名称”
- c# - 如何在我自己的类中配置依赖注入
- php - 如何将 CodeIgniter 中的 HOME 页面替换为 WordPress 的 HOME 页面,其他页面将保留在 CodeIgniter 中?
- python - umap-project 找不到供应商库