I was adding a new feature to an existing code base, causing some fairly large changes along the way. I opened one file to make some changes, but noticed the file could also be re-written in ES2016. So that's what I did. But it would make sense for me to commit just that single file change. To do that, I'd need to make sure it works in isolation - how can I do that when there's other changes in progress?

Turns out, quite easily. Here's how.

  • Add the files you want to commit with git add
  • Stash the leftover unstaged changes with git stash -k
  • Rebuild and re-test. If you have file watchers, this may even be automatic and very quick!
  • Now we're satisfied with that change in isolation, git commit
  • Bring bring the rest of your changes back with git stash pop