views:

636

answers:

3

How do I make diff ignore temporary files like foo.c~? Is there a configuration file that will make ignoring temporaries the default?

More generally: what's the best way to generate a "clean" patch off a tarball? I do this rarely enough (submitting a bug fix to an OSS project by email) that I always struggle with it...

EDIT: OK, the short answer is

diff -ruN -x *~ ...

Is there a better answer? E.g., can this go in a configuration file?

+3  A: 

This doesn't strictly answer your question, but you can avoid the problem by configuring Emacs to use a specific directory to keep the backup files in. There are different implementations for Emacs or XEmacs.

In GNU Emacs

    (defvar user-temporary-file-directory
      (concat temporary-file-directory user-login-name "/"))
    (make-directory user-temporary-file-directory t)
    (setq backup-by-copying t)
    (setq backup-directory-alist
      `(("." . ,user-temporary-file-directory)
        (,tramp-file-name-regexp nil)))
    (setq auto-save-list-file-prefix
      (concat user-temporary-file-directory ".auto-saves-"))
    (setq auto-save-file-name-transforms
      `((".*" ,user-temporary-file-directory t)))

In XEmacs

    (require 'auto-save) 
    (require 'backup-dir) 

    (defvar user-temporary-file-directory
      (concat (temp-directory) "/" (user-login-name)))
    (make-directory user-temporary-file-directory t)
    (setq backup-by-copying t)
    (setq auto-save-directory user-temporary-file-directory)
    (setq auto-save-list-file-prefix 
         (concat user-temporary-file-directory ".auto-saves-"))
    (setq bkup-backup-directory-info
      `((t ,user-temporary-file-directory full-path)))

You can also remove them all with a simple find command

    find . -name “*~” -delete

Note that the asterisk and tilde are in double quotes to stop the shell expanding them.

By the way, these aren't strictly temporary files. They are a backup of the previous version of the file, so you can manually "undo" your last edit at any time in the future.

Cheekysoft
A: 

You can create a small sunction/script to it, like:

#!/bin/bash
olddir="/tmp/old"
newdir="/tmp/new"

pushd $newdir
for files in $(find . -name \*.c)
do
  diff $olddir/$file $newdir/$file
done
popd

This is only one way to script this. The simple way. But I think you got the idea.

Other suggestion is configuring in emacs a backup dir, so your backup files go always to the same place, outside your work dir!

Fernando Barrocal
+2  A: 

You can create an ignore file, like this:

core.*
*~
*.o
*.a
*.so
<more file patterns you want to skip>

and then run diff with -X option, like this:

diff -X ignore-file <other diff options you use/need> path1 path2

There used to be a .diffignore file "close" to the Linux kernel (maybe an informal file), but I couldn't find it anymore. Usually you keep using this ignore-file, just adding new patterns you want to ignore.

rnsanchez