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

<p>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...</p>

<p>EDIT: OK, the short answer is</p>

<pre><code>diff -ruN -x *~ ...
</code></pre>

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

[{'answer_id': 33085, 'author': 'Cheekysoft', 'author_id': 1820, 'author_profile': 'https://Stackoverflow.com/users/1820', 'pm_score': 3, 'selected': True, 'text': '<p>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.</p>\n\n<p>In GNU Emacs</p>\n\n<pre>\n    (defvar user-temporary-file-directory\n      (concat temporary-file-directory user-login-name "/"))\n    (make-directory user-temporary-file-directory t)\n    (setq backup-by-copying t)\n    (setq backup-directory-alist\n      `(("." . ,user-temporary-file-directory)\n        (,tramp-file-name-regexp nil)))\n    (setq auto-save-list-file-prefix\n      (concat user-temporary-file-directory ".auto-saves-"))\n    (setq auto-save-file-name-transforms\n      `((".*" ,user-temporary-file-directory t)))\n</pre>\n\n<p>In XEmacs</p>\n\n<pre>\n    (require \'auto-save) \n    (require \'backup-dir) \n\n    (defvar user-temporary-file-directory\n      (concat (temp-directory) "/" (user-login-name)))\n    (make-directory user-temporary-file-directory t)\n    (setq backup-by-copying t)\n    (setq auto-save-directory user-temporary-file-directory)\n    (setq auto-save-list-file-prefix \n         (concat user-temporary-file-directory ".auto-saves-"))\n    (setq bkup-backup-directory-info\n      `((t ,user-temporary-file-directory full-path)))\n</pre>\n\n<p>You can also remove them all with a simple find command</p>\n\n<pre>\n    find . -name “*~” -delete\n</pre>\n\n<p>Note that the asterisk and tilde are in double quotes to stop the shell expanding them.</p>\n\n<p>By the way, these aren\'t strictly <em>temporary</em> 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. </p>\n'}, {'answer_id': 33098, 'author': 'Fernando Barrocal', 'author_id': 2274, 'author_profile': 'https://Stackoverflow.com/users/2274', 'pm_score': 0, 'selected': False, 'text': '<p>You can create a small sunction/script to it, like:</p>\n\n<pre><code>#!/bin/bash\nolddir="/tmp/old"\nnewdir="/tmp/new"\n\npushd $newdir\nfor files in $(find . -name \\*.c)\ndo\n  diff $olddir/$file $newdir/$file\ndone\npopd\n</code></pre>\n\n<p>This is only one way to script this. The simple way. But I think you got the idea.</p>\n\n<p>Other suggestion is configuring in emacs a backup dir, so your backup files go always to the same place, outside your work dir!</p>\n'}, {'answer_id': 1099613, 'author': 'rnsanchez', 'author_id': 72689, 'author_profile': 'https://Stackoverflow.com/users/72689', 'pm_score': 2, 'selected': False, 'text': '<p>You can create an ignore file, like this:</p>\n\n<pre><code>core.*\n*~\n*.o\n*.a\n*.so\n&lt;more file patterns you want to skip&gt;\n</code></pre>\n\n<p>and then run <code>diff</code> with <code>-X</code> option, like this:</p>\n\n<pre><code>diff -X ignore-file &lt;other diff options you use/need&gt; path1 path2\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 26330661, 'author': 'Bret Weinraub', 'author_id': 869942, 'author_profile': 'https://Stackoverflow.com/users/869942', 'pm_score': 0, 'selected': False, 'text': "<p>The poster has listed this as the 'short answer':</p>\n\n<pre><code>diff -ruN -x *~ ...\n</code></pre>\n\n<p>but feeding this to shell will cause the * to be globbed before diff is invoked.</p>\n\n<p>This is better:</p>\n\n<pre><code>diff -r -x '*~' dir1 dir2\n</code></pre>\n\n<p>I omit the -u and -N flags as those are matters of taste and not relevant to the question at hand.</p>\n"}]
['https://Stackoverflow.com/questions/33073', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1412/']