Question

I have made a major refactoring of some code, and in the process I have commited several times. This has not been pushed to any public repo yet. Before pushing, I would like now reorganize the commits into logical units. The problem is that I want not only to squash commits but to reorganze the hunks into other commits.

Just to make it clear, I have commit A with hunks A1, A2, A3, and commit B with hunks B1, B2, B3. I want to checkout the version previous to A and have new commit C with hunks A1, A2, B2 and a new commit D with hunks B1, B3, A3.

Thanks in advance.

Was it helpful?

Solution

Take a look at git rebase, splitting commits.

OTHER TIPS

It sounds like you want a completely different sets of commits. If that is the case, simply got back to the origin (e.g. git reset origin/master), and then use git add -p and git commit repeatedly until you are done. You can use git stash to test each commit after committing, if desired, and use git --amend to fix any mistakes.

Alternatively, git rebase -i can actually split commits. Read the man page, it's not hard but a bit bothersome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top