/dev/nikc/blog

Kuolleiden purjehduskenkien seura

Sep 3rd 2015

Complement Git Stash With Commit And Soft Reset

11:01

One of my favourite Git tools is the stash. However, it doesn’t always quite fit the bill. E.g. you notice you need to amend a commit in your history, but stashing everything would lead to solving umpteen unrelated conflicts during a rebase update. Instead I like to store everything irrelevant for the amend as a stash-commit, then stash what I need to bring along.

The Three Step Workflow

  1. git commit -am "stash", i.e. commit everything (you want to stash) into a stash-commit
  2. do your work, usually involves rebasing and/or working in other branches
  3. git reset HEAD^, i.e. reverse the stash-commit from stage 1

Stash Can Do That

The same effect (or very similar) can be achieved with stash save --patch, but I find a stash-commit is often quicker and simpler. Personally, I also like that my stash-commit remains in the branch, whereas stashes are global.

Stashes are also much too easy to forget, and even if you have the option to name them when using stash save, I rarely do, which leads to not remembering what’s been stashed if it’s more than minutes ago.

Shorts

Meta

Pages

Search blog

Latest comments