Normally, 'diff' tool finds only changes between lines. For example, if i compare 'abcdef' and 'AbcdEf', diff will show that 'abcde' is changed and 'f' is unchanged. Is it possible to find multiple changes per line, so in example above i will see that it's only 'a' changed to 'A' and 'e' changed to 'E'? Or diff outut format does not support such?
There are multiple diff tools that will do what you're asking for.
Off the top of my head I know Winmerge and TortoiseMerge does that.
I recommend KDiff3 which highlights with different colours changes on the same line.
I wrote a tool to diff web code regardless of differences from comments and whitespace. This means my tool can diff a completely minified file against a similar beautified file. It is written entirely in JavaScript so you try it directly in your browser without downloading or installing anything. This does highlight differences per line and highlights differences per characters on those lines.
http://prettydiff.com/
Related
how to do this, coloring lines (like git)?
here is an example where it is used: https://github.com/sveltejs/kit/discussions/7716
in markdown, in GitHub readme.
TLDR
add the symbol + and - (with diff syntax in markdown)
symbol
+
-
name
Addition
Deletion
color
Green
Red
what it does do?
code that being added or changed code
code that being deleted or removed
how to write it in MD?
```diff
-oldText
+newText
```
how it will look?
real example to copy and paste.
see here, I created a gist for you: https://gist.github.com/Laaouatni/1f0825dc0c531eb7cfb49ecc9560094c (click raw to copy code)
now you will be asking me,
why diff in particular?
by just going to google and searching: https://www.google.com/search?q=what+diff+means+linux
the first thing that came to my mind is the command diff, and I tried to search if diff is actually used in markdown, and it turns out that the info is true so it was real.
so use diff instead of javascript/python, or whatever...
https://gist.github.com/Laaouatni/1f0825dc0c531eb7cfb49ecc9560094c (click raw to copy code)
do I manually need to add the symbols?
I always suggest little lines... so it will be easier for you to manually add the symbols.
but if you have a lot of lines,
then you don't have to manually add + and -,
since if you have Linux just use the diff command, and will return you the text that you can copy and paste to GitHub.
by searching for differences in 2 files.
the command is something like this:
diff example1.txt example2.txt
if you are on windows, I am not pretty sure it will work or not, but try to see it here: What is the Windows equivalent of the diff command?, but yeah if it is only for 2 or maximum 10 lines I think writing manually can be time-saving... but you have entire pieces of code then do your research if you think it will worth the time.
attention:
by using a diff language name, now you can have this special design.
also, this works only in GitHub,
and you can't color highlight for a specified language like python or javascript for example...
example: there isn't any color highlighting
so use it when necessary to point out a breaking change for example.
GitHub's diff viewer has a nice feature that it has extra highlighting on changed lines. For example, in this diff, just a single word was inserted:
Are there other tools that display a diff like this? Pastebin's diff viewer and http://www.quickdiff.com/ don't do this, and even GitHub's gist doesn't do this if you tell it to highlight a .diff file.
I'd like some way to take two files or the output of diff and show this nice output without having to put it on GitHub. Does anything exist?
Kompare is able to highlight differences in a viewed patch, although it displays the file content in two different panes and not line over line like in your picture.
For diffing with highlighting I like KDiff3 better, but it will require two files to compare, it does not operate directly on patch files like kompare can.
In TortoiseSVN 1.5.1 I've noticed a curious pattern. If I change one line in a versioned file and then view difference the diff will highlight not only the changed line but also the last line of the file (though the last line hasn't changed and the colors in the highlight display that correctly).
Is there any use of this curious highlighting of the last line?
This bug was fixed in 1.5.7. See the changelog for details.
This could be a limitation of diff. Check if the file ends with a newline character.
GNU diff will mark incomplete lines (lines that are not terminated with a newline character) as changed, even if they have not because diff can't represent incomplete lines. See this diff doc
Some tools work around this limitation. Tortoise might not.
You could always check the last line to see if the file has changed. But I think you are right, pretty pointless :)
This is helpful, when the file has not been changed but the svn-metadata of the file have. When the diff highlights the last line without any previos change you can be sure that the file is unchanged and the metadata has changed.
Besides updating Tortoise, I would recommend using SourceGear DiffMerge. Tell Tortiose to use an external Diff Viewer and give it a command line like: C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe /t1=%bname /t2=%yname %base %mine.
It'll look like Tortoise but work much better.
This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know of a tool which can show the same (ex, via color) on the command line?
Another way to think of this is wanting to diff each difference in a patch file.
I don't know if this is sufficiently command line for your purpose, but vimdiff can do this (even does colour). See for example the image in this related question.
I tried all the tools I found: wdiff, dwdiff, kdiff3, vimdiff to show the difference between two long and slightly different lines. My favourite is diff-highlight (part of git contrib)
it supports diff format - great advantage over tools requiring two files like (dwdiff), e.g. if you need to visualize the output of unit tests
it highlights with black+white or with color if you connect it to colordiff
highlights characterwise - helpful for comparing long lines without spaces (better than wdiff)
Installation
On Ubuntu, you probably already have it as part of git contrib (installed within the git deb package).
Copy or link it into your ~/bin folder from /usr/share/doc/git/contrib/diff-highlight/diff-highlight
Usage example
cat tmp.diff | diff-highlight | colordiff
Result:
Another intuitive way to see all word-sized differences (though not side-by-side) is to use wdiff together with colordiff (you might need to install both). An example of this would be:
wdiff -n {file-A} {file-A} | colordiff
You can optionally pipe this into less -R to scroll through the output (-R is used to show the colors in less).
I had a similar problem and wanted to avoid using vimdiff. I found dwdiff (which is available in Debian) to have several advantages over wdiff.
The most useful feature of dwdiff is that you can customise the delimiters with -d [CHARS], so it's useful for comparing all kinds of output. It also has color built in with the -c flag.
You might be able to use colordiff for this.
In their man page:
Any options passed to colordiff are
passed through to diff except for the
colordiff-specific option 'difftype',
e.g.
colordiff --difftype=debdiff file1
file2
Valid values for 'difftype' are: diff,
diffc, diffu, diffy, wdiff, debdiff;
these correspond to plain diffs,
context diffs, unified diffs,
side-by-side diffs, wdiff output and
debdiff output respectively. Use these
overrides when colordiff is not able
to determine the diff-type
automatically.
I haven't tested it, but the side-by-side output (as produced by diff -y file1 file2) might give you the equivalent of in-line differences.
ccdiff is a convenient dedicated tool for the task. Here is what an example may look like with it:
By default, it highlights the differences in color, but it can be used on a console without color support too.
The package is included in the main repository of Debian:
ccdiff is a colored diff that also colors inside changed lines.
All command-line tools that show the difference between two files fall short in showing minor changes visuably useful. ccdiff tries to give the look and feel of diff --color or colordiff, but extending the display of colored output from colored deleted and added lines to colors for deleted and addedd characters within the changed lines.
I need to merge a forked project.
Unfortunately, the CVS $Id lines are different so the merge tools I tried report that all the files are different (and 95% of them have only this line different)
Is there a merge tool that can be configured to ignore line comparison results based on a pattern ?
[edit]
I discovered that WinMerge has line filters - setting up them correctly actually works.
Francesco
I use meld, which can use regex filters to ignore.
It has some preset ones you can select including CVS keywords.
The regex it uses for that BTW is:
\$\w+(:[^\n$]+)?\$
You can get meld on any linux distro or
download from here: http://meld.sourceforge.net/
I'm not sure how it's supported on windos,
but I do know kdiff3 supports windows so you could
give it a try there: http://kdiff3.sourceforge.net/
well you could use
cvs update -kk
whick does not expand the $words.
of course this is still a problems the $log which is expanded on commits and not updates.
CompareIT allow to use regular expression matching. I used it for automatically generated code comparison and it was very useful.