Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff --word-diff with oneline files

I'm having trouble with git diff --word-diff. The thing is when diff gets file without newlines (one line file) it differrs it line by line. And I want to differ it word by word.

Here's what happens when I'm comparing files without newlines:

git diff -a --word-diff=plain file1 file2
diff --git a/file1 b/file2
index 3526254..0515a63 100644
--- a/file1
+++ b/file2
@@ -1 +1 @@
[- a a a a a a a a a a-]
 No newline at end of file
 {+a a a a a ab a a a a+}

And if I add newline to the end of the files everything works as expected:

git diff -a --word-diff=plain file1 file2
diff --git a/file1 b/file2
index 1756d83..1ec45b9 100644
--- a/file1
+++ b/file2
@@ -1,2 +1,2 @@
 a a a a a [-a -]{+ab +}a a a a
like image 965
user1143094 Avatar asked Jan 11 '12 11:01

user1143094


People also ask

Can I use git diff to compare two files?

Git Diff Between CommitsYou can compare files between two Git commits by specifying the name of the ref that refers to the commits you want to compare. A ref may be a commit ID or HEAD, which refers to the current branch.

How do I see differences between files in git?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

How do I compare changes in two branches in git?

How do I compare two different branches in my Git repository? Using git-diff you can compare two branches by viewing a diff between them, or you can use git-log to view a list of commits that comprise the difference between them. Compare two branches with git diff branch1.. branch2 .

What is A and B in git diff?

Compared Files a/bOur diff compares two items with each other: item A and item B. In most cases, A and B will be the same file, but in different versions. Although not used very often, a diff could also compare two completely unrelated files with each other to show how they differ.


1 Answers

I wrote to GIT team and they answered that it is a bug indeed. Also they send me a patch for that case. Looks like it would be fixed in 1.7.9.

like image 96
user1143094 Avatar answered Dec 30 '22 19:12

user1143094