Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git apply doesn't create new files?

Tags:

git

diff

I'm trying to create patch by diff and apply it. My patch has new file and after apply I'm getting an error.

git diff master origin/master > patch1.diff
git apply patch1.diff -v

Checking patch test3...
error: test3: No such file or directory

Patch:

diff --git a/test3 b/test3
deleted file mode 100644
index df6b0d2..0000000
--- a/test3
+++ /dev/null
@@ -1 +0,0 @@
-test3

What I'm doing wrong or git apply doesn't create new files?

like image 453
Viacheslav Kondratiuk Avatar asked Mar 07 '13 22:03

Viacheslav Kondratiuk


People also ask

What is Apply command in git?

git-apply - Apply a patch to files and/or to the index.

How do I make a patch without committing?

Just make a new local branch and commit your changes there. You can always delete the branch later if you don't want it anymore, or you can keep the branch and use it for working on whatever you're doing, then merge (or rebase) it into the master branch when it's ready.


1 Answers

You're creating your patch backwards - that patch is trying to delete that file. I think you wanted:

git diff origin/master master > patch1.diff

You might find git format-patch to be helpful. If you currently have master checked out, you can just do:

git format-patch origin/master

That command will yield a bunch of patch files, one for each commit different between your branch and origin/master. You can then apply those using git am and retain all of the extra data like commit message and author information.

like image 84
Carl Norum Avatar answered Sep 19 '22 09:09

Carl Norum