How to Deal with Many Progress Commits

155 Views Asked by At

I like to commit often and for small, logical parts of code. If I'm working on a large feature (2+ weeks), there will be many commits such as:

  • Paged menu controller working
  • progress in XYZ (SAVING WORK AT END OF DAY so if laptop is lost, work is saved)

At the end of the feature, there are many commits and I fear that I'm polluting the commit history. I've considered Git squash, but it doesn't work once you pull in updates, or after you've pushed to your branch.

I'm considering just trying to have less-and-larger commits, and using squash locally on small commits before pushing to my fork feature branch. However, this would seem to hinder the detailed commit history that I like to have.

What is the best solution here?

1

There are 1 best solutions below

1
On BEST ANSWER

Even you have pushed your branches to remote, you can still squash your local commits and then force push to remote.

1. Squash commits

To squash commits on a branch, you can use git rebase -i branchname~n. while n is the amount commits you want to start squash.

Such as if you need to squash commits on feature branch(E, F, G and H as below graph) to a commit,

A---B---C---D develop
     \
      E---F---G---H   feature

you can use git rebase -i feature~4, then in the interactive windows, there will show the commits as:

pick E
pick F
pick G
pick H

You can need to change the last three commits F, G and H to squash. input i to insert, change them as:

pick E
squash F
squash G
squash H

Then enter Esc button and input :wq to exit interactive window. And the commits history will like:

A---B---C---D develop
     \
      E'  feature

2. Push changes to remote

Since you changed the history on branch, you should force push to remote by

git push -f