Dear moodlers,
Recently i ran into this challenge of creating a patch file for my changes made between commits.
according to moodle docs on git patch "git diff commitid1 commitid2 > patch.txt" didnt do the trick.
As the changes i did in commits were
1. Introduced new images(.png or .gif files) in commits
2. Created directory structures and created new files inside them.
can somebody tell me what is the procedure to include and preserve these in my patch ?
Hi,
I think the correct syntax is git diff commitid1..commitid2 (note two dots)
Hope that helps
I think the correct syntax is git diff commitid1..commitid2 (note two dots)
Hope that helps
If you have binary files (those PNGs), you want to add --binary:
git diff --binary commit1..commit2
But I tend to export them with
git format-patch --binary commit1..commit2
which gives you one patch per commit.
Thank you Penny and Martin for replying,
I created the patch using --binary but not able to test it as it fails to apply,
this is what i did
git diff --binary d6d26242d560183db9326ef8cbee6c1ac22a1e20..e7c9d7be8511f74a8b8a0ace87b5fa78e223fb0a > /var/www/patch.txt
Goku@Namek:/var/www/retest$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
Goku@Namek:/var/www/retest$ git checkout applypatch
Switched to branch 'applypatch'
Goku@Namek:/var/www/retest$ git status
# On branch applypatch
nothing to commit (working directory clean)
Goku@Namek:/var/www/retest$ sudo git apply /var/www/patch.txt
[sudo] password for Goku:
/var/www/patch.txt:377: trailing whitespace.
//Ravi => to enable adding roles in meta courses
/var/www/patch.txt:431: trailing whitespace.
/var/www/patch.txt:487: trailing whitespace.
/var/www/patch.txt:494: trailing whitespace.
/var/www/patch.txt:495: trailing whitespace.
error: patch failed: admin/roles/assign.php:1
error: admin/roles/assign.php: patch does not apply
error: patch failed: config.php:10
error: config.php: patch does not apply
I created the patch using --binary but not able to test it as it fails to apply,
this is what i did
git diff --binary d6d26242d560183db9326ef8cbee6c1ac22a1e20..e7c9d7be8511f74a8b8a0ace87b5fa78e223fb0a > /var/www/patch.txt
Goku@Namek:/var/www/retest$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
Goku@Namek:/var/www/retest$ git checkout applypatch
Switched to branch 'applypatch'
Goku@Namek:/var/www/retest$ git status
# On branch applypatch
nothing to commit (working directory clean)
Goku@Namek:/var/www/retest$ sudo git apply /var/www/patch.txt
[sudo] password for Goku:
/var/www/patch.txt:377: trailing whitespace.
//Ravi => to enable adding roles in meta courses
/var/www/patch.txt:431: trailing whitespace.
/var/www/patch.txt:487: trailing whitespace.
/var/www/patch.txt:494: trailing whitespace.
/var/www/patch.txt:495: trailing whitespace.
error: patch failed: admin/roles/assign.php:1
error: admin/roles/assign.php: patch does not apply
error: patch failed: config.php:10
error: config.php: patch does not apply
"fails to apply" means that there are other changes in those files that conflict with the changes you are trying to apply...
Shouldn't you reset your new branch to 'origin/master' before applying the patch?
Otherwise you'll be patching an already patched branch, won't you?
Saludos, Iñaki.
In this case master has the applied patches and thew ne branch called "applypatch" has unapplied code
Are they using the same repository? You may want to use "git merge" instead. Git is made to handle these things for you.
Dear Hubert chathi,
Am not trying to implement changes from one branch to another, i created a seperate branch and checkout to old code to test the patch that was created in master branch with latest code.
Am not trying to implement changes from one branch to another, i created a seperate branch and checkout to old code to test the patch that was created in master branch with latest code.
If it's a single commit (or a small number of commits) that you're testing, then "get cherry-pick" is useful.
If you want to test a patch for other users to use, then no, cherry-pick will not work. If that is what you are trying to do, then you need to either use patch directly ("patch < /var/www/patch.txt") or git apply.
either use patch directly ("patch
is some text that you intended to post got missed in above reply hubert ?
is some text that you intended to post got missed in above reply hubert ?
Actually, that is Moodle, which deletes everything after the first < character when cleaning input.
The point is that you need to use the command line patch tool, or another tool that can apply a patch.
The point is that you need to use the command line patch tool, or another tool that can apply a patch.
Dear Tim,
i used git apply to apply patch that i have created and faced problems, have posted the output that i got in previous replies.
dont know how to proceed. many people feel that the display is not providing much of info for them to help.
but even i am not able to find any other information for its failure to post it here.
please share your ideas regarding this.
i used git apply to apply patch that i have created and faced problems, have posted the output that i got in previous replies.
dont know how to proceed. many people feel that the display is not providing much of info for them to help.
but even i am not able to find any other information for its failure to post it here.
please share your ideas regarding this.
ok, an alternate command, without the character that Moodle filters out (Tim how did you get it to show up in your post?): "cat /var/www/patch.txt | patch -p1"
I've never used git apply, but patch usually tells you what chunks are conflicting, and creates *.rej files that show the conflicting chunks.
Anyways, from the output you posted so far, it looks like the patch is trying to modify admin/roles/assign.php and config.php and is encountering conflicts in those files.
I've never used git apply, but patch usually tells you what chunks are conflicting, and creates *.rej files that show the conflicting chunks.
Anyways, from the output you posted so far, it looks like the patch is trying to modify admin/roles/assign.php and config.php and is encountering conflicts in those files.
You can type <, if you are in safari, or another browser that does not use the HTML editor.
Dear Hubert chathi,
thanks for that, really helped.
Face another challenge now, i used
git format-patch --binary commitid1..commitid5
but this patch file dosent seem to create my pix folder and contents of it when applied.
thanks for that, really helped.
Face another challenge now, i used
git format-patch --binary commitid1..commitid5
but this patch file dosent seem to create my pix folder and contents of it when applied.