오늘:
3,121
어제:
8,468
전체:
5,151,798

오픈소스 이야기

2022.10.03 15:36

diff & patch

조회 수 1109 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

오픈소스에 대한 이해를 만화로 쉽게 할 수 있도록 작성한 컨텐츠를 원작자 님의 허락을 얻고 공유하고 있습니다.

공유를 허락해주신 원작자님에게 감사 드립니다.

원작자 : https://joone.net/

 

“diff와 patch는 무슨 툴인가?” 

잠깐 사용 방법을 소개하면,

hello_v1과 hello_v2 디렉토리에는 같은 hello.c라는 파일이 있지만, hello_v2에는 변경한 코드가 있습니다.

~/foss-comics-code/47.git/diff$ cat hello_v1/hello.c 

/* gcc hello.c -o hello */
#include <stdio.h>

int main() {
    printf("Hello World");
    return 0;
}

~/foss-comics-code/47.git/diff$ cat hello_v2/hello.c 


/* gcc hello.c -o hello */
#include <stdio.h>

int main() {
    printf("Hello World\n");
    return 0;
}

두 hello.c파일을 비교할 때, diff라는 툴을 사용합니다.

~/foss-comics-code/47.git/diff$ diff -u hello_v1 hello_v2
diff -u hello_v1/hello.c hello_v2/hello.c
--- hello_v1/hello.c 2022-09-05 18:37:24.894542803 -0700
+++ hello_v2/hello.c 2022-09-05 18:38:58.740332080 -0700
@@ -4,7 +4,7 @@
   
 int main() {
-    printf("Hello World");
+    printf("Hello World\n");
     return 0;
 }

위와 같이 두 파일을 차이를 쉽게 볼 수 있습니다. 자, 이제 이를 파일로 만들어서 hello.c를 만든 사람에 전달해봅시다.

~/foss-comics-code/47.git/diff$ diff -u hello_v1 hello_v2 > diff.patch
~/foss-comics-code/47.git/diff$ cat diff.patch 
diff -u hello_v1/hello.c hello_v2/hello.c
--- hello_v1/hello.c 2022-09-05 17:25:53.992894733 -0700
+++ hello_v2/hello.c 2022-09-05 17:27:51.091147715 -0700
@@ -4,7 +4,7 @@

 int main() {
-    printf("Hello World");
+    printf("Hello World\n");
     return 0;
 }

diff.patch라는 파일이 만들어졌습니다. 이제 이를 hello_v1/hello.c에 적용해봅니다.

~/foss-comics-code/47.git/diff$ patch -d hello_v1/ -p1 < diff.patch 

이렇게 하면 hello_v1/hello.c와 hello_v2/hello.c이 같아야 합니다. 확인해보겠습니다.

~/foss-comics-code/47.git/diff$ diff -u hello_v1 hello_v2
~/foss-comics-code/47.git/diff$ 

diff 명령어 결과가 없는 것으로 보아 두 파일이 같다는 것을 알 수 있습니다.

 

참고로, diff 명령어는 1970년대 초기에 벨랩에서 Unix 운영체제를 개발할 당시에 만들어진 툴입니다.

 

직접 diff와 patch 명령어를 사용해보세요!

https://github.com/joone/foss-comics-code/tree/main/47.git/diff

참고: diff와 patch 프로그램을 사용하는 방법 (https://kldp.org/node/28938)

 

  1. 오픈소스 이야기 게시판 이용안내

    Date2018.04.13 ByKevin Views2954
    read more
  2. 지속 가능한 오픈소스 프로젝트를 위한 가장 큰 기여는 후원

    Date2024.09.26 ByKevin Views1239
    Read More
  3. 2024년 오픈소스 현황 보고서

    Date2024.08.28 ByKevin Views2193
    Read More
  4. 리눅스 배포판 점유율(출처:랜스위퍼)

    Date2024.08.21 ByKevin Views5187
    Read More
  5. 리눅스는 인기가 있을까?

    Date2023.12.25 ByKevin Views3478
    Read More
  6. 오픈소스 세계의 짠한 현실

    Date2023.12.19 ByKevin Views2596
    Read More
  7. Python 프로그래밍 언어 2

    Date2023.04.25 ByKevin Views2345
    Read More
  8. Python 프로그래밍 언어 1

    Date2023.04.17 ByKevin Views2823
    Read More
  9. LLVM 프로젝트 (2/2)

    Date2023.01.20 ByKevin Views1994
    Read More
  10. LLVM 프로젝트 (1/2)

    Date2023.01.20 ByKevin Views2171
    Read More
  11. X-윈도우와 Wayland

    Date2022.11.03 ByKevin Views5993
    Read More
  12. GIT

    Date2022.10.03 ByKevin Views1648
    Read More
  13. quilt 사용하기

    Date2022.10.03 ByKevin Views1402
    Read More
  14. diff & patch

    Date2022.10.03 ByKevin Views1109
    Read More
  15. gpl-violations.org

    Date2022.09.02 ByKevin Views1187
    Read More
  16. KHTML

    Date2022.08.03 ByKevin Views1383
    Read More
  17. 파이어폭스

    Date2022.06.30 ByKevin Views1486
    Read More
  18. 넷스케이프 브라우저

    Date2022.05.16 ByKevin Views1392
    Read More
  19. 모자익 브라우저의 탄생

    Date2021.10.12 ByKevin Views1380
    Read More
  20. 월드와이드웹(WWW)의 시작 4

    Date2021.05.16 ByKevin Views1179
    Read More
  21. 월드와이드웹(WWW)의 시작 3

    Date2021.04.12 ByKevin Views1405
    Read More
Board Pagination Prev 1 2 3 4 ... 5 Next
/ 5
CLOSE