Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-diff: not taking line order into account

Tags:

git

git-diff

I have a file in my repository that is generated by a software program.

This program sometimes reorder the lines on that file, which is not really important because line order doesn't matter. The problem is that when performing git-diff it's very difficult to see whether anything has actually changed or not.

Is there anyway to perform a diff in which line order is not taken into account? Or, if not possible with git-diff, any shell command you might think of?

Thanks!

like image 508
Diego Herranz Avatar asked Dec 04 '13 13:12

Diego Herranz


1 Answers

At the end of the day, I'm manually running this command before committing to know whether the file actually changed or it's just a line reorder. Maybe I'll set up a git hook for it.

diff -wB <(sort file.txt) <(git show HEAD:file.txt | sort -)

This command compares the file in the working directory to the file in the last commit of your branch without taking the line order into account.

In my case, I use -w and -B, to ignore blank spaces and lines which the program also adds. From man diff:

   -w, --ignore-all-space
          ignore all white space
   -B, --ignore-blank-lines
          ignore changes whose lines are all blank
like image 75
Diego Herranz Avatar answered Nov 07 '22 00:11

Diego Herranz