diff and patch

root@test-desktop:/home/James/mypro/temp# more Makefile
ALL: test child
test: test.c
        gcc -Wall -o test test.c
child: child.c
        gcc -Wall -o child child.c
clean:
        -find ./ -name "test" -exec rm {} \;
        -find ./ -name "*~" -exec rm {} \;
root@test-desktop:/home/James/mypro/temp# cp Makefile makefile
root@test-desktop:/home/James/mypro/temp# cat >> makefile << EOF
> this is a test
> for diff
> and patch
> EOF
root@test-desktop:/home/James/mypro/temp# more makefile 
ALL: test child
test: test.c
        gcc -Wall -o test test.c
child: child.c
        gcc -Wall -o child child.c
clean:
        -find ./ -name "test" -exec rm {} \;
        -find ./ -name "*~" -exec rm {} \;this is a test
for diff
and patch
root@test-desktop:/home/James/mypro/temp# diff -uN Makefile makefile > makefile.patch
root@test-desktop:/home/James/mypro/temp# more makefile.patch 
--- Makefile    2012-06-13 11:53:59.983936223 +0800
+++ makefile    2012-07-17 17:36:30.868292187 +0800
@@ -5,4 +5,6 @@
        gcc -Wall -o child child.c
 clean:
        -find ./ -name "test" -exec rm {} \;
-       -find ./ -name "*~" -exec rm {} \;
\ 文件尾沒有 newline 字符
+       -find ./ -name "*~" -exec rm {} \;this is a test
+for diff
+and patch
root@test-desktop:/home/James/mypro/temp# patch -p0 makefile.patch 
^C
root@test-desktop:/home/James/mypro/temp# patch -p0 < makefile.patch 
patching file Makefile
root@test-desktop:/home/James/mypro/temp# more Makefile
ALL: test child
test: test.c
        gcc -Wall -o test test.c
child: child.c
        gcc -Wall -o child child.c
clean:
        -find ./ -name "test" -exec rm {} \;
        -find ./ -name "*~" -exec rm {} \;this is a test
for diff
and patch
root@test-desktop:/home/James/mypro/temp# patch -RE -p0 < makefile.patch 
patching file Makefile
root@test-desktop:/home/James/mypro/temp# more Makefile
ALL: test child
test: test.c
        gcc -Wall -o test test.c
child: child.c
        gcc -Wall -o child child.c
clean:
        -find ./ -name "test" -exec rm {} \;
        -find ./ -name "*~" -exec rm {} \;
root@test-desktop:/home/James/mypro/temp# 
相關文章
相關標籤/搜索