Подтвердить что ты не робот

Можно ли добавить комментарий в файл diff (унифицированный)?

Интересно, возможно ли добавить определенное количество нераспакованного содержимого в файл diff (унифицированный), который игнорируется как комментарий.

Одно из хороших способов использования этого метода заключалось бы в том, что git diffs дополняется важной информацией, например, из какой ветки этот diff отличается (особенно при использовании опции --full-index, которая просто отображает ссылки blob).

4b9b3361

Ответ 1

Унифицированный diff начинается с двух заголовков строк:

 --- from-file from-file-modification-time
 +++ to-file to-file-modification-time

Все, что перед этим заголовком игнорируется, поэтому вы можете добавить здесь любой комментарий, например:

 This may be some useful description of this patch that
 will be ignored by the diff/patch utility.
 --- a/foo  2002-02-21 23:30:39.942229878 -0800
 +++ b/foo  2002-02-21 23:30:50.442260588 -0800
 @@ -1,7 +1,6 @@
 -The Way that can be told of is not the eternal Way;
 -The name that can be named is not the eternal name.
  The Nameless is the origin of Heaven and Earth;
 -The Named is the mother of all things.
 +The named is the mother of all things.
 +
  Therefore let there always be non-being,
    so we may see their subtlety,
  And let there always be being,

Git сам использует это пространство перед заголовком для некоторых метаданных, например:

diff --git a/foo b/foo
index 59a4d1f..e48dfe7 100644
--- a/foo
+++ b/foo

Ответ 2

Вы можете использовать # вместо - или + в файле diff для встроенных комментариев (распознаваемых плагином GNU) или добавить комментарий в начале, указанном @JakubJirutka

 This may be some useful description of this patch that
 will be ignored by the diff/patch utility.
 --- a/foo  2002-02-21 23:30:39.942229878 -0800
 +++ b/foo  2002-02-21 23:30:50.442260588 -0800
 @@ -1,7 +1,6 @@
 # comments on the deletion of the two lines
 -The Way that can be told of is not the eternal Way;
 -The name that can be named is not the eternal name.
  The Nameless is the origin of Heaven and Earth;
 -The Named is the mother of all things.
 +The named is the mother of all things.
 +
  Therefore let there always be non-being,
    so we may see their subtlety,
  And let there always be being,

Ответ 3

Все, что после @@на той же строке также игнорируется.

 --- a/foo  2002-02-21 23:30:39.942229878 -0800
 +++ b/foo  2002-02-21 23:30:50.442260588 -0800
 @@ -1,7 +1,6 @@ THIS IS A COMMENT THAT WILL BE IGNORED
 -The Way that can be told of is not the eternal Way;
 -The name that can be named is not the eternal name.
  The Nameless is the origin of Heaven and Earth;
 -The Named is the mother of all things.
 +The named is the mother of all things.
 +
  Therefore let there always be non-being,
    so we may see their subtlety,
  And let there always be being,