Reputation: 3074
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
Upvotes: 0
Views: 689
Reputation: 13001
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.
Upvotes: 1
Reputation: 73625
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.
Upvotes: 2