java - 让 git 忽略连续的换行符
问题描述
我想在 git 中只跟踪代码(java),我想让它忽略从先前提交中添加的多个换行符(如果没有其他代码已更改)例如:
我想要这个
class MyApp{
public static void main(String[] args) {
if (args.length > 0) {
for(String s : args){
system.err.println("arg is "+s+"\n");
}//end-for
}//end-if
}//end-met
}//end-class
和这个:
class MyApp{
public static void main(String[] args) {
if (args.length > 0) {
for(String s : args){
system.err.println("arg is "+s+"\n");
}//end-for
}//end-if
}//end-met
}//end-class
被视为相同(仅当添加了非换行符时,代码才应视为不同)
这样做的目的是避免在仅添加噪声时复制同一文件(如果我在 git 中搜索文件,我只想在发生“实际”代码更改时获取)
解决方案
Git 没有提供忽略对跟踪文件的更改的方法。
如果你想在提交之前格式化文本,你可以使用一个干净的过滤器(在属性中指定.gitattributes
)filter
以你想要的任何方式自动格式化它。gitattributes(7)
您可以在手册页中查看如何执行此操作的文档。否则,Git 无法实现您的目标。
推荐阅读
- java - 来自 ArrayList 的 JDBC createArrayOf
- javascript - 需要点击2次才能关闭一个div
- r - x[[method]](...) 中的错误:在获取文件时尝试在 testthat 测试中应用非函数
- c# - 为什么 StreamReader.ReadLine() 忽略我的换行符?
- php - 从数据库获取数据后添加反斜杠
- groovy - Groovy 字符串和日期戳
- php - 在 Woocommerce 中用自定义文本标签替换零或空显示价格
- php - Codeigniter 锚标记超链接到控制器中的表单,但数据显示在表外
- reactjs - awsmobile 配置 -> 错误:标头内容包含无效字符
- java - 如何使用 LocalDate - Java 获得一个月中的工作日数量