git-diff:不考虑行顺序

Die*_*anz 10 git git-diff

我的存储库中有一个由软件程序生成的文件.

该程序有时会对该文件中的行重新排序,这并不重要,因为行顺序无关紧要.问题是,当执行git-diff时,很难看出是否有任何实际改变.

无论如何都要执行不考虑行顺序的差异?或者,如果不能使用git-diff,你可能会想到任何shell命令?

谢谢!

Die*_*anz 8

在一天结束时,我在手动运行此命令,然后才知道文件是否实际更改了,或者只是一个行重新排序.也许我会为它设置一个git hook.

diff -wB <(sort file.txt) <(git show HEAD:file.txt | sort -)
Run Code Online (Sandbox Code Playgroud)

此命令将工作目录中的文件与分支的上次提交中的文件进行比较,而不考虑行顺序.

在我的例子中,我使用-w-B忽略程序也添加的空格和行.来自man diff:

   -w, --ignore-all-space
          ignore all white space
   -B, --ignore-blank-lines
          ignore changes whose lines are all blank
Run Code Online (Sandbox Code Playgroud)