Development/gerrit/SplitPatch
TDF LibreOffice Document Liberation Project Community Blogs Pootle Nextcloud Redmine Ask LibreOffice Donate
Split a patch after it was uploaded to gerrit
So, you have uploaded a patch to gerrit and your reviewer said: "Please split it in two patches". Well, it is clear what the reviewer want, ... but how to do this? Well this is only a matter of couple git commands:
get a change
first you start and donwload the gerrit patch and create a branch from there
git fetch https://gerrit.libreoffice.org/core refs/changes/42/1/42 && git checkout FETCH_HEAD
git checkout -b split_that_change
start a rebase process
now we are going to start rebase and say in dialog edit for your commit and save & exit:
git rebase -i HEAD^
unstage your changes
now we are going to unstage the file in your commit:
git reset HEAD^
pick up files you want to preserve in your first change
now we are going to pick up files that should stay in your first change
git add foo
Note: if you do commit this way:
git commit -m "my first change"
you are going to lose your ChangeId. To preserve it, copy it from your last commit and paste it in your editor where your are writing the commit message. In this way it wouldn't be overriden by commit-hook.
git commit
# enter the commit message and paste your ChangeId from your original commit
pick up files that are going in your second change
git add bar
git commit
# and enter the commit message (new ChangeId is going to be generated)
complete the rebase operation
now we complete the rebase operation:
git rebase --continue
swap the order of commits (optionally)
Depends on your concrete change if your changes are related to each other you shoud care of the order of your changes. If you need to swap the order of changes then you have to rebase again:
git rebase -i HEAD~2
# change the order of two commits in e editor, save & exit
Now push
Note: if you are going to do it with git-review
you would get a warning, that you are going to upload more than once change. In this case it is okay, just say yes ... in the end we do know what we are doing ;-)