Git: apply patches ¶
Purpose
Retrieve changes from a remote "working clone" of a project to your local development machine
On remote "working clone" ...
where you've done some changes to be recovered, procede as follows:
- Move changes to be recovered to a work branch, and commit them:
git stash git checkout -b dirty git stash apply git add . git commit -m "my new nice changes"
- Check the id of the new commit:
$ git log --oneline eddc3c6 (HEAD -> dirty) my new nice changes ...
- Build a single patch file referring to the specific commit:
git format-patch -o patches/ -1 eddc3c6
or
git format-patch -o patches/ -1 HEAD
- Sent it to the developer:
http://brainstorm.it/snippets/send-email-command-line/
or download from development machine via rsync:
rsync -a --rsync-path="sudo rsync" master@host:/home/project/project/patches .
- Later (after the changes have been integrated in the main project), you might want to cleanup your working clone:
git checkout master git branch -D dirty rm -fr ./patches
On your development machine ...
Apply the changes:
$ git am patches/0001-retrieve_avatars-fixes.patch
Note that, as a result of applying the patch, the changes have already been committed to your working branch:
$ git log --oneline de4ccec (HEAD -> master) my new nice changes