DEV Community

Discussion on: Up your Git game and clean up your history

Collapse
 
joemcmahon profile image
Joe McMahon

More often than not I've got one of those commit histories that look like the "OH LORD WHAT HAVE I DONE" graph, and even rebase is hard to use to clean up -- this happens most often when I have something that fixes one thing, but needed two or more changes. (I really should get into the habit of committing after each file change, even if it leaves HEAD broken.)

In those cases, I use a process of checking out master into a cleanup branch, git cherry-pick -n (i.e., don't commit) the changes from the branch I'm cleaning up onto the cleanup branch, and then git reset. Now all of the commits are squashed on a per-file basis. I then repeatedly use git add -p to build a new set of per-file commits that catch me up by replying y until the next change would go into a new file. Then commit and repeat until all the changes have been built into commits.

It loses the commit order, but very nicely collects the changes into per-file changes. Hm. This might have been better as a post instead of a comment!