Applying a diff file with git

后端 未结 6 1584
一个人的身影
一个人的身影 2021-02-18 20:50

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

相关标签:
6条回答
  • You will have to check if you still see the error message bad git-diff - expected /dev/null on line 47 after Git 2.17 (Q2 2018).

    Many places in "git apply" knew that "/dev/null" that signals "there is no such file on this side of the diff" can be followed by whitespace and garbage when parsing a patch, except for one, which made an otherwise valid patch (e.g. ones from subversion) rejected.

    See commit e454ad4 (15 Feb 2018) by Tatyana Krasnukha (tkrasnukha).
    See commit f16ef7b (15 Feb 2018) by Johannes Schindelin (dscho).
    (Merged by Junio C Hamano -- gitster -- in commit 177bd65, 28 Feb 2018)

    See also git-for-windows/git issue 1489

    apply: handle Subversion diffs with /dev/null gracefully

    Subversion generates diffs that can contain lines like this one:

    --- /dev/null (nonexistent)

    Let's teach Git's apply machinery to handle such a line gracefully.

    0 讨论(0)
  • 2021-02-18 21:15

    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.

    0 讨论(0)
  • 2021-02-18 21:21

    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.

    0 讨论(0)
  • 2021-02-18 21:27

    I had the same issue.

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

    Or, if I convert all line-endings to Unix format:

    error: patch failed: <file>:81
    error: <file>: patch does not apply
    ...
    

    git apply --ignore-whitespace <patch>.patch worked with Unix line-endings.

    0 讨论(0)
  • 2021-02-18 21:29

    I had the same problem You have a rebase in progress, write

    git rebase --skip 
    

    many times, until see No rebase in progress? then try again with git am

    0 讨论(0)
  • 2021-02-18 21:36

    I had the same issue, but I was testing a patch I was going to send to a listserve, following the recommendations here: https://www.kernel.org/doc/Documentation/email-clients.txt . I couldn't just fix the problem on my local file, I needed to distribute a patch which was potentially going to be mangled by gmail and I was checking the gmailed version with git apply.

    My co-worker pointed out to me that

    git am 
    

    Is better than git apply at correcting for these sorts of problems and is what should be used with .patch files. This is mentioned in one of the comments above but it should be an answer.

    0 讨论(0)
提交回复
热议问题