Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "git diff header lacks filename information when removing 1 leading pathname component " when executing git apply

I created a diff file by a command:

git --no-pager diff --no-index --stat pathA pathB >\diff.log

Nextly, I executed a command:

git apply --index --ignore-space-change --ignore-whitespace \diff.log

During the execution I encountered an error:

error: git diff header lacks filename information when removing 1 leading pathname component (line 2138)

Line 2138 leads to:

2136 diff --git a/C:\Temp\right_tmp5D66/file.cpp b/file.cpp

2137 new file mode 100644

2138 index 0000000000000000000000000000000000000000..e69de...

2139 diff --git ......

I have tried a command "git apply --reject ..." but it also didn't work. I also added config which ignores chmod changes (git config core.fileMode false) and nothing was changed.

like image 684
krawat10 Avatar asked Jan 02 '19 18:01

krawat10


2 Answers

Most probably because you have this setting in the git config (~/.gitconfg):

[diff]
  noprefix = true

So, you can remove it or change to false:

git config --global diff.noprefix false

like image 123
milushov Avatar answered Sep 20 '22 15:09

milushov


you can try this.

patch -p0 < filename

This patch command reads a source file's instructions on how to change a file, then applies the changes. The source file contains difference listings (or diff listings) and one or more sets of diff command output, like called hunks.

The patch command skips any leading text in a patch file, applies the actual diff listing, and skips any trailing text. Thus, you could use as a patch file or message that includes a diff listing, and the patch command would still work. In such a case, if the entire diff listing is indented by a consistent amount, the patch command will also adjust for that spacing.

  • p0 leaves the entire path name unmodified.
like image 41
vignesh Avatar answered Sep 20 '22 15:09

vignesh