git cheats: simple squash

I posted about how to squash commits. This is a pretty common thing to do with git when merging feature branches into master. I discovered an easier way to do this. This won't be acceptable for many scenarios, but if you don't care about the commit history on your branch and you just want to quickly get the changes on your branch committed to master in one shot with a single commit, use git reset:

git checkout master  
git pull --rebase  
git merge your-feature-branch  
git reset origin/master  
git add --all  
git commit  

This will:

  • switch to master
  • ensure it's up to date
  • apply the changes on your feature branch (all commits)
  • reset will whipe the commits, but leave the local, no-disk changes
  • you're now free to commit these to master as a new commit
comments powered by Disqus