|
From: Tait <gnu...@t4...> - 2017-11-17 21:59:26
|
Ethan A Merritt via gnuplot-beta <gnu...@li...> said (on 2017/11/17): > Here's part of the problem I'm having with tracking ChangeLog in git. > > Suppose that a git format-patch file contains a ChangeLog entry that is > supposed to go at the top of the current ChangeLog file. Like this: > > diff --git a/ChangeLog b/ChangeLog > index 9ca7eee..285597c 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -0,0 +1,4 @@ > +2017-11-17 Ethan A Merritt <merritt@u.washington.edu> > + > + git does not like this diff format > + > > The entire patch file containing this piece is rejected by "git apply" > or "git am", apparently because it does not like the syntax "@@ -0,0" > which diff/patch use to indicate "top of file". > > I can apply the patch manually using "patch" and then run "git commit", > but this loses the commit message and author information that was in > the original formatted patch. > > Is there some config option for "git am" and/or "git apply" that tells > it to accept this syntax in a patch file? > > Note: "patch" will also accept "@@ -1,0" rather than "@@ -0,0" but > git doesn't like this form either. > > Ethan How was this patch-file generated? Git refuses to apply a patch with no context, and usually does not generate one. So in the ChangeLog example, the patch, whether generated by "git diff" or "git format-patch" would normally be generated with three context lines, and look something like: diff --git a/ChangeLog b/ChangeLog index 9ca7eee..285597c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-11-17 Ethan A Merritt <merritt@u.washington.edu> + + git does not like this diff format + =============================================================================== If you are seeing this you must have obtained a snapshot of gnuplot development from the development cvs repository on sourceforge.net. This is out of date! You can reduce it down to a single line of context, and the patch will still apply: diff --git a/ChangeLog b/ChangeLog index 9ca7eee..285597c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,1 +1,5 @@ +2017-11-17 Ethan A Merritt <merritt@u.washington.edu> + + git does not like this diff format + =============================================================================== But using zero lines of context, as in "@@ -0,0 +1,4 @@", does not apply. Even generating the patch with "git format-patch -U0" and applying it verbatim on the same commit it was generated from, will fail. There is an option to git-apply, "--unidiff-zero", to force application even with no context, but it does not appear that this option has been extended to git-am. If you are adding a new file, then obviously there is no context to provide. In this case, git uses the special "old" filename of /dev/null as an indicator that there is no prior context, and this seems to be required. Example: diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 9ca7eee..285597c 100644 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,4 @@ +2017-11-17 Ethan A Merritt <merritt@u.washington.edu> + + git does not like this diff format + You'll notice it also adds the "new file mode" above the index line, but the mode line does not seem to be strictly required for the patch to apply. |