Changes between Initial Version and Version 1 of GitRejectedPatch


Ignore:
Timestamp:
Jul 29, 2013, 1:58:20 PM (11 years ago)
Author:
Piero Campalani
Comment:

Copy dev-list discussion

Legend:

Unmodified
Added
Removed
Modified
  • GitRejectedPatch

    v1 v1  
     1= Dealing with rejected patches =
     2
     3It can often happen that a patch you submitted to the [http://rasdaman.org/patchmanager Patch Manager] gets rejected by our benevolent dictator, especially if you're a new dev and you are not that familiar yet with the rasdaman [http://rasdaman.org/wiki/CodeGuide coding guidelines].
     4
     5In case you are not familiar with `git` neither, here's a couple of examples of possible solutions that apply to such situations.
     6
     7SCENARIO: you formatted a patch `pZ` for commit `Z` in your local branch `my_branch` on top of `A`.
     8The `master` branch is a clean and synced copy of the `origin/master` remote branch, hence the public HEAD of rasdaman:
     9
     10{{{
     11  o-------o-------A-------B-------C  [master] -> [origin/master]
     12                   \
     13                    \   X--> rejected!
     14                     \ /-pZ
     15                      Z  [my_branch]
     16}}}
     17
     18This is usually a recommended developing workflow, so if you worked directly on your local `master`, you might want to switch to this layout:
     19
     20{{{
     21#!sh
     22$ git stash
     23$ git checkout -b my_branch master
     24$ git checkout master
     25$ git fetch origin
     26$ git reset --hard origin/master
     27HEAD is now at `D' <ticket:XYZ - Brief description of this patch>
     28$ git branch
     29 * master
     30   tmp
     31}}}
     32
     33Now the local `master` is synced with the patches that surely in the meantime were accepted in the [http://rasdaman.org/patchmanager Patch Manager].
     34The other (local) branch `my_branch` contains your rejected commit `Z`.
     35
     36At this point there can be possible solution in order to rework on the patch:
     37
     38
     39== 1. [Rebase &] amend ==
     40
     41If there are not patches which were applied since your rejection (ie `B` and `C`, see above), you can avoid rebasing: your `my_branch` branch is still on top of `origin`'s HEAD.
     42
     43Otherwise firstly you can move `my_branch` on top of `D`:
     44
     45{{{
     46  o-------o-------A-------B-------C  [master] -> [origin/master]
     47                   .               \
     48                    .               \
     49                     Z --(rebase)--> Z  [my_branch]
     50}}}
     51
     52
     53Afterwards, you can ''amend'' your commit: you can simply do it by modifying the files you are required to -- also files not previously included in the `Z` commit, stage them, then re-commit with the `--amend` option. You also have the chance to change the title of your patch during the process, eg `Z~`
     54
     55{{{
     56#!sh
     57$ vim file1 file2 ... fileN
     58[do your stuff]
     59$ git add file1 file2 ... fileN
     60$ git commit --amend
     61[you can change the title here now through your configured $GIT_EDITOR]
     62}}}
     63
     64{{{
     65  o-------o-------A-------B-------C  [master] -> [origin/master]
     66                                   \
     67                                    \
     68                                    Z~  [my_branch]
     69}}}
     70
     71Now you can reformat the patch:
     72
     73{{{
     74#!sh
     75$ git format-patch HEAD~
     760001-Z~.patch
     77}}}
     78
     79Look out there are no other new patches in `origin`:
     80
     81{{{
     82#!sh
     83$ git fetch origin
     84}}}
     85
     86Otherwise you can also try to see if your patch does not conflict with new ones: for instance while you were fixing your patch, a new one (`D`) was accepted:
     87
     88{{{
     89  o-------o-------A-------B-------C-------D  [master] -> [origin/master]
     90                                   \
     91                                    \
     92                                    Z~  [my_branch]
     93}}}
     94
     95Instead of re-rebasing, you can try:
     96
     97{{{
     98#!sh
     99$ git checkout master
     100$ git merge origin/master
     101$ git apply --check 0001-Z~.patch
     102}}}
     103
     104If no output is printed, then you can submit the new patch: http://rasdaman.org/patchmanager.
     105
     106
     107== 2. Cherry-pick ==
     108
     109An other possible solution, which might be easier in case your rejected patch has already been followed by tons of other patches you formatted
     110and that were accepted, is cherry-picking.
     111
     112For instance, a patch `pZ` (for your `Z` commit) was rejected, then a new patch from some other dev was accepted (`B`), and an other patch you developed afterwards on top of `Z` was accepted (patch `pW` for bringing local commit `W` to the public repo as `W~`):
     113
     114{{{
     115  o-------o-------A-------B-------W~  [master] -> [origin/master]
     116                   \             /----> accepted
     117                    \   X-------/-----> rejected!
     118                     \ /-pZ    /-pW
     119                      Z-------W  [my_branch]
     120}}}
     121
     122
     123You can clone your master to a new branch and cherry-pick your `Z` but without creating a new `Z` ''commit'', just taking its changes:
     124
     125{{{
     126#!sh
     127$ git checkout master
     128$ git fetch origin
     129$ git merge origin/master
     130$ git checkout -b my_other_branch master
     131$ # Pick Z (refs/heads/my_branch~):
     132$ git cherry-pick refs/heads/my_branch~ --no-commit
     133$ git status
     134[changes in Z are staged now]
     135}}}
     136
     137{{{
     138  o-------o-------A-------B-------W~  [master] -> [origin/master]
     139                   \               \
     140                    \   o-(c-pick)-(Z~) [my_other_branch]
     141                     \ /
     142                      Z-------W  [my_branch]
     143}}}
     144
     145This way you can now fix the changes, re-stage them and commit.
     146
     147----
     148
     149Final note: conflicts can always happen, it's not your fault.[[BR]]
     150https://duckduckgo.com/?q=git+rebase+conflict