Skip to content
Kristian Larsson edited this page Aug 5, 2014 · 2 revisions

So, you have submitted a pull request (PR) but we asked you to change some stuff to align with our design guidelines or similar and now your history looks like crap;

commit b876f4f887196760e79558f7511416b45ad904e5
Merge: 248a194 5b35385
Author: John Smith <john@smith.com>
Date:   Mon Jul 28 12:55:12 2014 +0200

    Use pynipap functions instead of writing my own
    
    Whopsie dopsie, seems there are already existing functions for 
    some of the stuff I want to do, better use them.

commit 5b35385dbd35fb67dcc33ae7b32120bea06eac85
Author: John Smith <john@smith.com>
Date:   Fri Jul 25 17:34:01 2014 +0200

    Fix indent.

    Stupid NIPAP team ask me to do indent with spaces.. well well.
    
commit 248a19436bbc64bbeded9d17b7e4c9253a40a87e
Merge: 74ef42f eb4728b
Author: John Smith <john@smith.com>
Date:   Sun Jul 27 00:33:13 2014 +0200

    Add super duper awesome feature FOO
    
    This adds FOO which is like soooo cool that noone will be able to
    live without it.

We want NIPAP to have a clean history that doesn't show all the little changes you've done over time as separate commits but rather to have a few number of commits, each being a solid piece of code that represents a milestone in your work. Big features which add a lot of changes are certainly allowed to be more than one commit, just try to keep it neat. For more information, please see https://www.reviewboard.org/docs/codebase/dev/git/clean-commits/

Anyway, we want to merge all those commits into one clean commit. Since we don't care much for the two later commits (they are just fixes), we can merge those right away;

git rebase -i HEAD~3

You will be presented by your editor and something that looks like;

pick 2116c68 Add super duper awesome feature FOO
pick eb4728b Fix indent.
pick 5b35385 Use pynipap functions instead of writing my own

# Rebase 14692cb..b876f4f onto 14692cb
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

To meld the two later commits into your first, simply replace "pick" with "fixup" or "f";

pick 2116c68 Add super duper awesome feature FOO
f eb4728b Fix indent.
f 5b35385 Use pynipap functions instead of writing my own

And exit your editor. Git will now do some magic and your history will now only contain the one entry.

You could also choose 's' to squash your commit into the previous one and edit the commit message to reflect your changes.

Since you have now rewritten history, you won't be able to push your changes like normal. The easiest thing to do is remove your remote branch and push the new version again;

git push my-remote :my-branch
git push -u my-remote my-branch

Your code should now be in your feature branch on GitHub - Submit a new PR!

Also see our recommendations on good branch names.