問題描述
忽略 diff 中的 Emacs 自動生成的文件 (Ignore Emacs auto‑generated files in a diff)
如何讓 diff
忽略 foo.c~
等臨時文件?是否有一個配置文件可以忽略臨時文件?
更一般地說:從 tarball 生成“乾淨”補丁的最佳方法是什麼?我很少這樣做(通過電子郵件向 OSS 項目提交錯誤修復),以至於我總是在努力解決它......
編輯:好的,簡短的回答是
diff ‑ruN ‑x *~ ...
是有更好的答案嗎?例如,這可以放在配置文件中嗎?
參考解法
方法 1:
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.
方法 2:
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.
方法 3:
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!
方法 4:
The poster has listed this as the 'short answer':
diff ‑ruN ‑x *~ ...
but feeding this to shell will cause the * to be globbed before diff is invoked.
This is better:
diff ‑r ‑x '*~' dir1 dir2
I omit the ‑u and ‑N flags as those are matters of taste and not relevant to the question at hand.
(by Chris Conway、Cheekysoft、rnsanchez、Fernando Barrocal、Bret Weinraub)