Tip from the team: save your changes for later

Supported Platforms

  • macOS
  • Windows

 

One of the more common tasks of any developer's day is discarding work in progress, especially when switching branches for a 'quick' code review or to whip up a hotfix, and being able to manage that efficiently is key to unlocking productive workflows. Not to mention those times when you've been testing tweak after tweak, getting nowhere, and just want to get back to where you started without a lot of hassle. You might be tempted to copy the modified files or quickly make a copy of the whole directory and just go through diff after diff later but there's a painless, straightforward alternative.

homer.jpg

 

Keep it safe

What if I told you that both Git and Mercurial already know how save your changes and restore them later to finish and commit when you're ready? Well guess what… they do! Each might handle it a little bit differently under the hood but they are fundamentally the same behavior.

Reminder: saved changes are kept in your local working copy and never sent to a remote server; don't delete them or your working copy accidentally

  • Git saves your current changes ("stash" in their terminology), automatically referencing the branch you're saving the changes from. You can optionally keep changes you've already staged and include a message to remind yourself about this particular stash.
  • Mercurial saves your current changes ("shelve" in their terminology), independent of any particular branch or tag. You'll need to give the shelved set of changes a meaningful, non-conflicting name. 

Sourcetree makes doing this easily accessible from the Repository menu, its keyboard shortcut, and the toolbar item.

stash_create_win.gifstash_create.gif

 

Return to work

Once you're ready to dust off these changes and get back to them it's equally easily. You'll either "Apply Stash" (Git) or "Unshelve" (Mercurial) a particular set of saved changes and all you need to do is double-click on the entry in Sourcetree's sidebar or use the corresponding menu item. You're also given the choice of whether or not to delete that set of saved changes once it's been re-applied. If you're not quite sure yet keep them around and you can delete it later from the contextual menu.

stashapply_win.gifstash_apply.gif

 

Do you have your own stash tip or maybe even a favorite custom action to expand on what's built into Sourcetree? Feel free to comment below!

 

Additional Reading:

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events