diffscope: file, directory, archive diff

search_compdiffscope is a Debian utility to compare files archives and directories. It does not have any merge or editing capabilities but it can extract and show differences in multiple binary file formats. It is useful when you want to track differences between archives, directory contents or PDFs. Continue reading diffscope: file, directory, archive diff

QGit & Diffuse: Git GUI on Linux

qgit_compI was looking for a good GUI based Git repository browser to view changes. To speak the truth, the terminal is not really the best option to look at a overwhelming number of change records which need to be examined in detail and in reasonable time. There are many Git GUI interfaces on Linux but some of them are bulky and some lack finesse. I found QGit to be exactly the tool I needed.

QGit features

  • Very lightweight. Written using Qt/C++.
  • Auto branch configuration detection
  • Shows everything you need to understand a change: commit history (including range), change log for individual commit, diff, modified file list
  • Can launch an external diff viewer like Diffuse
  • File tree view that helps to track commits to a single file
  • Save a patch series to send for review, apply a patch at any revision, view a patch
  • User defined keyboard shortcut for Actions
  • Commit, amend commit, make branch, make tag
  • Available by default in the repositories for major distros

QGit integrates seamlessly with Diffuse, a graphical file diff viewer. Diffuse is one of the few diff-merge tools that supports N-ary file merge. However, one of its most powerful features is the support for version control systems. Diffuse is written in Python.

Diffuse

Diffuse features

  • Merge N number of files side by side in different panes
  • Manually adjust line matching and directly edit files
  • Integrates with file manager menu
  • Modify both left and right side files (2-way merge)
  • Retrieve revisions of files from Bazaar, CVS, Darcs, Git, Mercurial, Monotone, SVN and SVK repositories for comparison and merging

Installation

To install QGit and Diffuse on Ubuntu, run:

$ sudo apt-get install qgit diffuse

Webpage: QGit, Diffuse

tig

Tig is an ncurses-based text-mode interface for git. It functions mainly as a Git repository browser, but can also assist in staging changes for commit at chunk level and act as a pager for output from various Git commands. To browse a git repository navigate inside a versioned directory and run tig. To install tig on Ubuntu:

$ sudo apt-get install tig

Compare files on Linux

tux_compThere was a time I used WinMerge regularly on Windows for comparing files. When I switched completely to Linux I had to find an alternative. Cmdline utilities like vimdiff are OK but I was looking for something in GUI so that the learning curve is easier. Here are a few such file compare tools which are very lightweight and do the job very well. All of these support 3-way file compare.

  • Diffuse: Fast and cool GUI. Written in python. This should be your choice if you are intimidated by KDiff3. Supports changing file in all panes. Multiplatform.

  • SourceGear DiffMerge: I found it a little less flexible as it allows you to modify only the file in the RHS in 2-way merge. The toolbar icons seemed a little big and it would have been better if the current difference could be highlighted with a different colour to make that more readable. But it is still a very good utility. Multiplatform.

  • KDiff3: The king of its kind on Linux though not very easy to use till you get used to it. I have written about it earlier.

kdiff3-qt: file compare and diff on Linux

If you are looking for a powerful file compare and diff utility on Linux you can try kdiff3. It was originally developed for the KDE environment but if you are on Gnome you can try the qt port of the tool kdiff3-qt. It supports 2 and 3-way merges for files and directories. Once you select the input files, select Merge Current File icon and you are good to go. Uses an additional pane to show the merged output.

If you are looking for directory synchronization check out the multiplatform FreeFileSync.

Another console based utility is vimdiff. A nice and short tutorial here.

Webpage: kdiff3

Using diff and patch on Linux

tux_compApplying patches with patch

To apply a patch to a single file, change to the directory where the file is located and call patch:

patch < foo.patch

These instructions assume the patch is distributed in unified format, which identifies the file the patch should be applied to. If not, you can specify the file on the cmdline:

patch foo.txt < bar.patch

Applying patches to entire directories (perhaps the more common case) is similar, but you have to be careful about setting a “p level”. What this means is that, within patch files, the files to be patched are identified by path names which may be different now that the files are located on your computer rather than on the computer where the patch was created. The p level instructs patch to ignore parts of the path name so that it can identify the files correctly. Most often a p level of one will work, so you use:

patch -p1 < baz.patch

You should change to the top level source directory before running this command. If a patch level of one does not correctly identify any files to patch, inspect the patch file for file names. If you see a name like

/users/stephen/package/src/net/http.c

and you are working in a directory that contains net/http.c, use

patch -p5 < baz.patch

In general, count up one for each path separator (slash character) that you remove from the beginning of the path, until what’s left is a path that exists in your working directory. The count you reach is the p level.

To remove a patch, use the -R flag, ie

patch -p5 -R < baz.patch

Creating patches with diff

Using diff is simple whether you are working with single files or entire source directories. To create a patch for a single file, use the form:

diff -u original.c new.c > original.patch

To create a patch for an entire source tree, make a copy of the tree:

cp -R original new

Make any changes required in the directory new/. Then create a patch with the following command:

diff -rupN original/ new/ > original.patch

That’s all you need to get started with diff and patch. For more information use:

man diff
man patch

The original article is here. It’s brief and to the point. I couldn’t have written better.

Linux binary editors and file diff viewers

Systems programmers need a hex editor frequently. Here are some options:

  1. A file can be viewed/edited in hex mode from vi using the :%!xxd and :%!xxd -r combination but it is not too strong and needs careful editing.
  2. An efficient and easy to use cmdline tool for editing files in hex mode is ncurses-hexedit which is available in Synaptic package manager on Ubuntu. The editor has many options like search, go to location, insert, delete bytes etc. which are more than enough for regular usage. After installing the package, run:
    $ hexeditor filename
  3. hexedit
  4. lfhex
  5. le
  6. hexcurse
  7. wxHex Editor has a GUI and is multiplatform. It can support massive files.
If you are looking for a hex file compare utility cum editor:
  1. VBinDiff: can compare and edit files.
  2. dhex: only diff viewer.
  3. cmp: options.
  4. xdelta