| 21 | There are two possible ways in order to create a patch: |
| 22 | |
| 23 | === Way 1 === |
| 24 | * create a local branch on top of master: |
| 25 | {{{ |
| 26 | git checkout -b foobar #if you are on master |
| 27 | }}} |
| 28 | * Do some work inside this branch. |
| 29 | * Have a look what has changed really: |
| 30 | {{{ |
| 31 | git status |
| 32 | }}} |
| 33 | * Add all files which shoul go into the patch in order to track them: |
| 34 | {{{ |
| 35 | git add src/file1.c po/file2.po maint/file3.txt |
| 36 | }}} |
| 37 | * Create a diff against master: |
| 38 | {{{ |
| 39 | git diff master > /tmp/newpatch.patch |
| 40 | }}} |
| 41 | * Delete everything which was done: |
| 42 | {{{ |
| 43 | git reset --hard $sha_of_last_usefull_commit |
| 44 | }}} |
| 45 | Using here --soft will also work but then you'll have to delete the untracked stuff on your own |
| 46 | * Check if something is still there which shouldn't be there |
| 47 | {{{ |
| 48 | git status |
| 49 | }}} |
| 50 | * Switch back to master and delete the foobar branch |
| 51 | {{{ |
| 52 | git checkout master |
| 53 | git branch -d foobar |
| 54 | }}} |
| 55 | |
| 56 | === Way 2 === |
| 57 | * Do some work in the master branch |
| 58 | * Add all files which should show up in the diff into the stagging area |
| 59 | {{{ |
| 60 | git add file1 file2 file3 |
| 61 | }}} |
| 62 | * Create patchfile: |
| 63 | {{{ |
| 64 | git diff master > /tmp/patchfile.patch |
| 65 | }}} |
| 66 | * Reset master to last usefull commit: |
| 67 | {{{ |
| 68 | git reset --hard $sha_of_last_usefull_commit |
| 69 | }}} |
| 70 | * Check if something is still there which shouldn't be there |
| 71 | {{{ |
| 72 | git status |
| 73 | }}} |
| 74 | |
| 75 | === Discussing the patch === |
| 76 | As a patch should always be build on master it should be fairly trivial to test if the patch is okay (applies): |
| 77 | For this only fetch the patch and apply it on master (or on a foobar branch for testing). Maybe test if the patch behaves as expected and read through the patch if the coding style and the changes itself are good. |
| 78 | After that comment on the ticket if the patch is okay or should reworked. |
| 79 | |
| 80 | Afterwards you can clean up again the master branch with |
| 81 | {{{ |
| 82 | git reset --hard $sha_of_last_usefull_commit |
| 83 | }}} |
| 84 | |
| 85 | === Applying the patch on master === |
| 86 | |
| 87 | There are a lot of other possibilities in order to create patches/work on the git but I would suggest that you try it on your own ;-) |