Search code examples
gitreview-board

Splitting one commit into 2 and get the resulting diff


I recently posted a diff to review board at work. I didn't really check the diff until after and I noticed that whitespace at the end of lines was removed by my editor. I'd like to split those whitespace changes out into a separate commit. How can I do this?

Afterward, I think the easiest way to update the diff would be to actually just upload the diff. There have been a bunch of commits since my commit and I've rebased since (we always pull --rebase here) so just updating review board using the guess features might not work out really.

Note: I've already pushed.


Solution

  • I'm not familiar with "review board," but here's a general git strategy for answering this part of the question:

    I'd like to split those whitespace changes out into a separate commit. What would be the easiest way to do this.

    git checkout whitespace-fix
    git reset --hard <sha of commit you posted diff of>
    git reset HEAD~1
    git add --patch .
    

    Now stage the hunks that correspond to the whitespace issues (tip: use "s" to split presented hunks into smaller hunks). After you're done, commit and rebase and your fresh commit is ready.

    git commit -m 'Remove whitespace at end of lines'
    git rebase master