Diff: Difference between revisions

add quick directory comparison
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
Tags: Mobile edit Mobile web edit
 
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 ===
=== 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'.
Or, piping to <code>awk</code> to print a list of just what's in the 'left side'.
<source lang="bash">
<syntaxhighlight lang="bash">
diff --suppress-common-lines --side-by-side modules.list.a.txt modules.list.b.txt |awk '{print $1}'
diff --suppress-common-lines --side-by-side modules.list.a.txt modules.list.b.txt |awk '{print $1}'
</source>
</syntaxhighlight>


=== Process Substitution ===
=== Process Substitution ===
By using process substitution, we can operate on the output of commands without the need for saving to a file.
By using process substitution, we can operate on the output of commands without the need for saving to a file.
<source lang="bash">
<syntaxhighlight lang="bash">
drush pml --status=enabled --pipe > modules.list.txt
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
# 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
diff --suppress-common-lines --side-by-side <(drush pml --status=enabled --pipe) modules.list.txt
</source>
</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:
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:
<source lang="bash">
<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/)
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/)
</source>
</syntaxhighlight>




Line 52: 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 87: 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)
?
?