忽略差異中的Emacs自動生成的文件 (Ignore Emacs auto-generated files in a diff)


問題描述

忽略 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 ConwayCheekysoftrnsanchezFernando BarrocalBret Weinraub)

參考文件

  1. Ignore Emacs auto‑generated files in a diff (CC BY‑SA 2.5/3.0/4.0)

#autosave #emacs #diff #backup #patch






相關問題

保存 NSDocument 時收到通知 (Get notified when NSDocument is saved)

忽略差異中的Emacs自動生成的文件 (Ignore Emacs auto-generated files in a diff)

如何在 OSX 應用程序中恢復窗口位置? (How to restore window position in an OSX application?)

使用沒有保存按鈕的 Symfony 爬蟲發送表單(自動保存功能) (send form with Symfony crawler without save button (autosave function))

如何在 NumericTextbox Kendo UI 滾動條中觸發自動保存 (How to trigger autosave in a NumericTextbox Kendo UI Scrollbars)

自動保存草稿的最佳做法? (Best practices for autosaving drafts?)

如何在 iPhone 應用程序上存儲多個帳戶的用戶登錄詳細信息(用戶、密碼) (How to store user Login details(user, pass) for multiple accounts on iPhone app)

從 OSX lion 上的版本瀏覽器恢復不起作用...想法? (Restoring from versions browser on OSX lion not working... ideas?)

是否有visual studio自動保存配置設置? (Is there a visual studio automatic save configuration setting?)

用戶退出應用程序時在 MapKit 中存儲註釋 (Store annotations in MapKit when user quit application)

Umbraco 全部內容自動保存 (Umbraco Whole Content Autosaving)

是否有使用 MVC 架構(asp.net、c#、jquery、ajax)自動保存冗長 Web 表單數據的 API/解決方案 (Is there an API/ solution for Auto-saving data of lengthy web forms using MVC architecture (asp.net,c#,jquery,ajax))







留言討論