Nice programing

svn diff 또는 git diff에서 at 기호가있는 "@@… @@"메타 라인은 무엇을 의미합니까?

nicepro 2020. 12. 12. 12:28
반응형

svn diff 또는 git diff에서 at 기호가있는 "@@… @@"메타 라인은 무엇을 의미합니까?


내가 사용할 때 svn diff또는 git diff다음과 같은 줄이 표시됩니다.

@@ -1,5 +1,9 @@

무슨 뜻입니까?


이를 (c) hunk 헤더라고하며 범위 정보를 포함합니다.

그들은 이중 표지판에 둘러싸여 @@있습니다. 형식은 다음과 같습니다.

@@ -l,s +l,s @@

여기서는 l시작 줄 번호이고 s변경 (c) hunk가 각 파일에 적용되는 줄 수입니다. -원본 파일을 나타내고는 +새로운 (수정) 파일을 나타냅니다. 영향을받은 줄뿐만 아니라 컨텍스트 줄도 표시합니다.

-1,5원본 파일에 있습니다 (로 -표시됨). 첫 번째 줄이 시작이고 5 개의 영향을받는 / 컨텍스트 줄임을 보여줍니다.

(가) +1,9제 (의해 새로운 지시 (수정) 파일에 +) 다시 첫번째 라인은 처음 9 영향 / 컨텍스트 라인이다.

자세한 내용은 여기 : http://en.wikipedia.org/wiki/Diff#Unified_format


간단한 예제 분석

형식은 기본적으로 diff -u통합 diff 와 동일합니다 .

예를 들면 :

diff -u <(seq 16) <(seq 16 | grep -Ev '^(2|3|14|15)$')

여기에서 2, 3, 14 및 15 행을 제거했습니다. 출력 :

@@ -1,6 +1,4 @@
 1
-2
-3
 4
 5
 6
@@ -11,6 +9,4 @@
 11
 12
 13
-14
-15
 16

@@ -1,6 +1,4 @@ 방법:

  • -1,6첫 번째 파일의이 부분이 1 행에서 시작하여 총 6 행을 표시 함을 의미합니다. 따라서 1 ~ 6 행을 표시합니다.

    1
    2
    3
    4
    5
    6
    

    -"오래된"을 의미하며 일반적으로 diff -u old new.

  • +1,4두 번째 파일의이 부분은 1 행에서 시작하여 총 4 행을 표시 함을 의미합니다. 따라서 1 ~ 4 행을 표시합니다.

    + "새로운"을 의미합니다.

    2 개 라인이 제거 되었기 때문에 6 개 대신 4 개 라인 만 있습니다! 새로운 덩어리는 다음과 같습니다.

    1
    4
    5
    6
    

@@ -11,6 +9,4 @@ for the second hunk is analogous:

  • on the old file, we have 6 lines, starting at line 11 of the old file:

    11
    12
    13
    14
    15
    16
    
  • on the new file, we have 4 lines, starting at line 9 of the new file:

    11
    12
    13
    16
    

    Note that line 11 is the 9th line of the new file because we have already removed 2 lines on the previous hunk: 2 and 3.

Hunk header

Depending on your git version and configuration, you can also get a code line next to the @@ line, e.g. the func1() { in:

@@ -4,7 +4,6 @@ func1() {

This can also be obtained with the -p flag of plain diff.

Example: old file:

func1() {
    1;
    2;
    3;
    4;
    5;
    6;
    7;
    8;
    9;
}

If we remove line 6, the diff shows:

@@ -4,7 +4,6 @@ func1() {
     3;
     4;
     5;
-    6;
     7;
     8;
     9;

Note that this is not the correct line for func1: it skipped lines 1 and 2.

This awesome feature often tells exactly to which function or class each hunk belongs, which is very useful to interpret the diff.

How the algorithm to choose the header works exactly is discussed at: Where does the excerpt in the git diff hunk header come from?


These describe the lines affected by the diff hunk. In your case, it means the hunk affects 5 lines starting from line 1, resulting in a replacement starting at line 1 which is 9 lines long.

Note that this is the format used by the unified diff format. The "classical" diff format uses a different model (but who uses classical diff these days?).

참고URL : https://stackoverflow.com/questions/8558597/what-does-the-meta-line-with-at-signs-in-svn-diff-or-git-diff-mean

반응형