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?
git-apply - Apply a patch to files and/or to the index.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With