June 08, 2019
Sometimes you only want to stash a few files at a time.
Maybe in the course of your work, the files you were changing revealed a bigger, more urgent problem. You don’t want to lose your work, but you want to be able to cut a new branchy off of master to address the new problem.
Before you can go back to master, pull down the most recent files, however, you need to clear your git log.
git stash is a great way to do that.
git stash push <path/to/file>
$ git status On branch feature/doing-things Your branch is up to date with 'origin/feature/doing-things'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: package-lock.json modified: src/App/MyComponent.js no changes added to commit (use "git add" and/or "git commit -a")
Okay, so I have changed files, but I want to only stash the
$ git stash push src Saved working directory and index state WIP on feature/3207-tracks-to-favorites-map-changes: 7316117cf5 Removed consoles. $ git stash show 0 ...App/MyComponent.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
git stash push srcwas enough to distinguish that I didn’t want to stash my
Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!