deltaskelta deltaskelta - 3 months ago 14
Git Question

git: cleanup or delete commit to cleanup the commit history

The docs and searching is just confusing me about what to do to cleanup a commit history.

Say I have a branch called tests that I use to push builds to travis-ci and I have a build failing. I would then have to make some small commits to try to fix the error message and re-push the

tests
branch.

This could lead to a chain of small and nearly pointless commits that I do not really want to make, but I am forced to nonetheless. How would I compact these into one commit? I think
rebase
is what I am looking for but I am confused about a few things.

If I use
squash
, I find that I run into a ton of merge conflicts that I have to then go and solve manually.

I think the solution may be to just delete the commits, but then I am not sure if I will be deleting some history that my final "working" commit needs.

Say my commit history looks like this:

commit1: some new feature
commit2: crap, builds failing, trying fix
commit3: more build attempts
commit4: Ahh I think I got it this time
commit5: ok finally fixed, build passing


Now I would essentially like to have only one commit to merge back into the
master
. What would you do here that isn't going to lead to merge conflicts?

Answer

How about

git reset --soft HEAD~[n]
git commit

That should squash your n last commits.