It sometimes happen you need change code on a machine from which you cannot push to the repo.
You’re ready to copy/paste what diff
outputs to your local working copy.
You think there must be a better way to proceed and you’re right. It’s a simple 2 steps process:
1. Generate the patch:
git diff > some-changes.patch
2. Apply the diff:
Then copy this patch to your local machine, and apply it to your local working copy with:
git apply /path/to/some-changes.patch
And that’s it! The changes are now in your working copy and ready to be staged/commit/pushed :)
If you run
git diff
it will show changes that were tracked previously. But newly added files are not shown in the diff. To create a patch, I did the following.git add -A
# Add everything to the staging area.git diff --staged --patch > changes.patch
#--staged
shows all the changes including new filesgit reset
# Reset to the old stateNow, I can apply the changes.
Edit: I just checked
git diff --staged --patch
andgit diff --staged
by creating two new patch files, and comparing them with thediff
command. I don't find any difference.