我的問題是類似Interactive program to selectively exclude parts of a diff file - 但有點不同......區分感知編輯器,可以處理修補程序塊編輯(包括刪除行)?
說我有以下的「原生態」的文件:
$ cat test-orig.h
int varA;
int varB;
int varC;
int varD;
int varE;
...說我做了這些改變成「新」文件:
$ cat test-newmodified.h
int varA;
int varB;
int varC;
// a couple of lines
// of useless comments
int var_extra1;
int var_extra2;
int varD;
int varE;
然後兩者之間的差異是:
$ diff -Naur test-orig.h test-newmodified.h | tee test.patch
--- test-orig.h 2013-07-18 19:21:25.741027138 +0200
+++ test-newmodified.h 2013-07-18 19:21:19.916998200 +0200
@@ -1,5 +1,9 @@
int varA;
int varB;
int varC;
+// a couple of lines
+// of useless comments
+int var_extra1;
+int var_extra2;
int varD;
int varE;
那麼假設我有一個這樣獲得的補丁文件(有很多人),我想刪除「無用的評論」。從diff
生成的補丁文件中刪除整個大塊通常很容易 - 但是如果我只想刪除一些行,那麼diff計數器(上面的@@ -1,5 +1,9 @@
)也必須進行修改。再說了,如果註釋行是在文件中刪除,該差異將被:
$ diff -Naur test-orig.h test-newmodified-nc.h
--- test-orig.h 2013-07-18 19:21:25.741027138 +0200
+++ test-newmodified-nc.h 2013-07-18 19:26:30.898540270 +0200
@@ -1,5 +1,7 @@
int varA;
int varB;
int varC;
+int var_extra1;
+int var_extra2;
int varD;
int varE;
...也就是說,有意見,@@ -1,5 +1,9 @@
計數器 - 成了現在,沒有註釋,@@ -1,5 +1,7 @@
。
如果我只是刪除補丁test.patch
註釋行(並保存編輯爲test-edit.patch
),並且不更新計數器,然後我得到:
$ patch -p0 <test-edit.patch
patching file test-orig.h
patch: **** malformed patch at line 10:
......而這樣的補丁沒有按沒有得到應用。那麼,如果我只是改變了+1,9
到+1.7
在test-edit.patch
,那麼它適用乾淨:
$ patch -p0 <test-edit.patch
patching file test-orig.h
...和預期test-orig.h
改變(不註釋行)。
因此,給定一個補丁文件,其中包含與文件有關的所有宏塊都包含在內 - 是否有一個(GUI)(文本)編輯器,它是diff
意識到(至少,統一比較),以便:當來自hunk(或整個hunk)被刪除,它會自動更新diff計數器 - 這樣編輯後的補丁文件仍然會乾淨地應用於原始文件?
Emacs是操作系統和Linux爲內核。有可能你不會找到更好的解決方案。 – devnull