Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying a diff file with git

Tags:

So I was trying to use apply a diff file to my git dev branch. The diff I wanted to apply was this one here: https://github.com/mbabker/joomla-cms/compare/JHtml_move.patch

I used git apply PATH_TO_PATCH.patch

Now on trying to apply it I get a load of errors cumulating with a

fatal: git apply: bad git-diff - expected /dev/null on line 47 

Thing is line 47 reads --- /dev/null

I saw on another forum somebody say there was a trailing white space after the /dev/null part but there isn't.

In case its any help I'm also being thrown errors of trailing white spaces on lines 9, 10, 11, 12 and 13 - despite their NOT being any trailing white spaces.

In any case the diff is being generated by git - I'm just copying and pasting it into notepad.

I've also tried using curl https://github.com/mbabker/joomla-cms/compare/JHtml_move.patch | git am but that just gives an error without specifying location.

Error message from curl attempt

Any ideas as to why its giving an fatal error when the line actually exists????


Update to @IvanZuzak I tried adding in the git am --ignore-space-change --ignore-whitespace PATH_TO_PATCH.patch however I got first of all (as this was the downloaded patch) an error saying the email was invalid (it had been converted to html code) so I tried to fix that but it kept throwing it up every now and again. Then it said previous rebase directory PATH_TO_GITHUB_BRANCH/.git/rebase-apply still exists but mbox given.. So I found this which suggested removing the rebase-apply folder in the branches .git folder. So I did that and then I got the invalid email error again (despite I'd changed both ones away from the html formatted)

like image 336
George Wilson Avatar asked Apr 10 '13 18:04

George Wilson


People also ask

Can you git diff a specific file?

The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.

How do I use a diff file?

Applying a DIFF File in the Command LineCopy the DIFF files to the root directory of your store. Open the terminal on the server or access the server remotely via SSH. Replace /path/to/cscart/root/directory with the actual path to the root directory of your store. Replace example.

What is git diff format?

By default, git diff command options will display the unified diff format between two commits. The combined diff format shows two or more user-specified files with one file and shows how that file is different from each of the specified files. You can use the -c or --cc option to produce a combined diff.


2 Answers

I also had the same problem:

fatal: git apply: bad git-diff - expected /dev/null on line 47 

Yet line 47 reads --- /dev/null. The problem I found was that the line endings were in Windows format instead of UNIX format. Converting the line endings to UNIX format in Notepad++ fixed the problem for me.

like image 133
Garrett Avatar answered Oct 31 '22 05:10

Garrett


I had the same issue. I opened up Git Bash (Cygwin works as well) and did:

dos2unix.exe <patch-file> 

Then I was able to apply the patch perfectly fine.

like image 44
bigosmallm Avatar answered Oct 31 '22 03:10

bigosmallm