5

I've seen lots of blog posts about using git commit --amend, or rebasing to squash commits.

I find it a bit easier to git reset to the last checkpoint (say before all my 'save point' microcommits) and then use interactive adding to pick out the best order of commits.

Is there a downside to this?
I'm wondering b/c as most of the blogs I read use amend or rebase for this purpose

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ambertch
  • 7,581
  • 4
  • 28
  • 40

2 Answers2

6

The downside is for you to pick again all the individual files in order to group them again in commits.

If your commits needs to be grouped together (without having to add or remove files in those commits), then a rebase --interactive is easier: you reason in term of set of files committed.
Actually, with the right commit comments, a rebase --interactive --autosquash can do the reordering for you.

If your commits are purely intermediate save point, without much thought as their composition in term of set of files, then your solution is adequate.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

To add to what VonC answered, it depends how many commits you have too.

What happens to me most often is something like this:

  • Work on A, commit
  • Work on B, commit
  • Oh no! I missed something important in A, commit correction for A

With an interactive rebase, it is trivial to reorder then squash the correction into the original commit for A.

Another example is when I just want to reword a commit message.

Yet another example is when I have something like this

A-------------------master
 \
  B-----C-----D-----branch

and I want to incorporate C & D but not B into master. I can use rebase to reorder my branch commits to C, D, B, then git checkout master and git merge D

Benjol
  • 63,995
  • 54
  • 186
  • 268