Development/gerrit/SplitPatch

    From The Document Foundation Wiki

    Split a patch after it was uploaded to gerrit

    You have uploaded a patch to gerrit and your reviewer said: "Please split it into two patches". It is clear what the reviewer wants, but how to do this? This is only a matter of a couple of git commands.

    Get a change

    Start by downloading 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

    Start rebase, save and exit:

    git rebase -i HEAD^

    Unstage your changes

    Unstage the file in your commit:

    git reset HEAD^

    Pick up files you want to preserve in your first change

    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 into the editor where you are writing the commit message. In this way it wouldn't be overridden by commit-hook.

    git commit 
    # enter the commit message and paste your ChangeId from your original commit

    Pick up files that are going into your second change

    git add bar
    git commit 
    # and enter the commit message (new ChangeId is going to be generated)

    Complete the rebase operation

    git rebase --continue

    Swap the order of commits (optionally)

    Depending on your concrete change and the relation of your changes to each other, you should take care about the order of your changes. If you need to swap the order of changes, you have to rebase again:

    git rebase -i HEAD~2
    # change the order of two commits in the editor, save and exit

    Now push

    See: How to submit patches

    Note: if you are going to do it with git-review you would get a warning, that you are going to upload more than one change. In this case it is okay, just say yes, in the end you do know what you are doing.