tags:

views:

170

answers:

2

Hello,

My git commits are a bit messed up and I was wondering if I could squash them all together and then "extract" some commits from that commit.

Let's say I have these files in one commit: upload.py, moderate.py, upload.html, moderaion.html

How can I split it in two commits like this? upload: upload.py, upload.html

moderation: moderate.py, moderaion.html

+2  A: 

First you can squash all the commits together with git rebase --interactive X (where X is the parent of the commits you want to squash). After that run git rebase --interactive X a second time, but now split the squashed commit as described in git-rebase's manual.

Before you start rebasing, it's best to mark down the current head commit. Write down its hash or create a new tag/branch. That way you can easily revert all your changes and try again.

Esko Luontola
No need for tagging or writing down hash now that there is reflog on by default (HEAD@{1}, @{1}, etc.)
Jakub Narębski
True. But it's easier when you don't need to figure out whether it was @{1}, @{2} or something else after making lots of operations that modify the head.
Esko Luontola
+1  A: 

You question implies that the commits are already messy, but if the commits themselves are 'atomic' but just in the wrong order, you can also use git rebase --interactive to put them in the right order and then squash them. This might make things more easy for you.

If the commits already touch several areas and you want to split them up, again, git rebase -i can help. Also have a look at the example at Bart's blog.

Mark van Lent
The blog had all the answers. Thanks
Patrick Marechal