Diff: Difference between revisions

No edit summary
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
Tags: Mobile edit Mobile web edit
 
(3 intermediate revisions by one other user not shown)
Line 11: Line 11:
: diff -rq --exclude .svn path/to/directoryA path/to/directoryB
: diff -rq --exclude .svn path/to/directoryA path/to/directoryB
E.g.
E.g.
<source lang="bash">
<syntaxhighlight lang="bash">
diff -rq -x .svn ./work/myproject/ ./work/myproject-copy2/
diff -rq -x .svn ./work/myproject/ ./work/myproject-copy2/
</source>
</syntaxhighlight>
 
=== Piping ===


The <code>diff</code> command is fast, but often the output is hard to read to find the exact difference.  You might try piping the output of the diff command to a graphical tool:
The <code>diff</code> command is fast, but often the output is hard to read to find the exact difference.  You might try piping the output of the diff command to a graphical tool:
<source lang="bash">
<syntaxhighlight lang="bash">
diff fileA fileB | kdiff3 -
diff fileA fileB | kdiff3 -
</source>
</syntaxhighlight>
By using the dash option to kdiff3, you're telling it to read from STDIN, so it uses the output of the former commands being piped to it.
By using the dash option to kdiff3, you're telling it to read from STDIN, so it uses the output of the former commands being piped to it.
Or, piping to <code>awk</code> to print a list of just what's in the 'left side'.
<syntaxhighlight lang="bash">
diff --suppress-common-lines --side-by-side modules.list.a.txt modules.list.b.txt |awk '{print $1}'
</syntaxhighlight>
=== Process Substitution ===
By using process substitution, we can operate on the output of commands without the need for saving to a file.
<syntaxhighlight lang="bash">
drush pml --status=enabled --pipe > modules.list.txt
# make a bunch of changes to what modules are enabled, perhaps restoring from a backup, and compare to our original list
diff --suppress-common-lines --side-by-side <(drush pml --status=enabled --pipe) modules.list.txt
</syntaxhighlight>
This technique comes in handy if you wish to compare two directories at their top level. The '''extensions''' directory, for example, in [[MediaWiki]] from two different installations:
<syntaxhighlight lang="bash">
diff --suppress-common-lines --side-by-side <(ls -1 /var/www/wiki.example.net/www/w/extensions/) <(ls -1 /var/www/wiki.example.org/www/w/extensions/)
</syntaxhighlight>


=== Compressed files ===
=== Compressed files ===
Line 29: Line 52:
=== Configuring ===
=== Configuring ===
You can configure KDiff3 to ignore Version Control keywords, or do other fancy things to assist the matching portion of the KDiff execution.  This is one of the most powerful features of KDiff3
You can configure KDiff3 to ignore Version Control keywords, or do other fancy things to assist the matching portion of the KDiff execution.  This is one of the most powerful features of KDiff3
<source lang="bash">
<syntaxhighlight lang="bash">
sed 's/\$\(Revision\|Author\|Log\|Header\|Date\).*\$/\$\1\$/'
sed 's/\$\(Revision\|Author\|Log\|Header\|Date\).*\$/\$\1\$/'
</source>
</syntaxhighlight>
Enter <pre>help:/kdiff3/preprocessors.html</pre> in Konqueror to read up on preprocessing commands
Enter <pre>help:/kdiff3/preprocessors.html</pre> in Konqueror to read up on preprocessing commands


Line 64: Line 87:


Example of diff across the network to look at repository URLs using the command-line subversion client invoking an external visual diff program instead of the built-in diff tool:
Example of diff across the network to look at repository URLs using the command-line subversion client invoking an external visual diff program instead of the built-in diff tool:
<source lang="bash">
<syntaxhighlight lang="bash">
svn diff --diff-cmd kdiff3 \
svn diff --diff-cmd kdiff3 \
http://svn.example.com/svn/myrepo/path/to/file.txt@7560 \
http://svn.example.com/svn/myrepo/path/to/file.txt@7560 \
http://svn.example.com/svn/myrepo/path/to/file.txt@HEAD
http://svn.example.com/svn/myrepo/path/to/file.txt@HEAD
</source>
</syntaxhighlight>
GUI subversion clients such as kdesvn or TortoiseSVN have the same capability: built-in differencing or optional setting to invoke an external differencing tool.  For KDESvn it's 'Settings'->'Configure kdesvn'->'Diff & Merge' (screenshot provided)
GUI subversion clients such as kdesvn or TortoiseSVN have the same capability: built-in differencing or optional setting to invoke an external differencing tool.  For KDESvn it's 'Settings'->'Configure kdesvn'->'Diff & Merge' (screenshot provided)
?
?