Git stash has many common operations that can be represented by following commands.

git stash
git stash list
git stash pop [–index] [stash_id]
git stash apply [–index] [stash_id]
git stash drop [stash_id]
git stash clear

Now we will learn a few other powerful options.

git stash push

After October 2017, the command git stash save has been deprecated in favor of the alternative git stash push because git stash push has the option pathspecs but git stash save does not support.

We can use the command to handle a few files rather than all changed and tracked files. git stash save always handles all changed files which are tracked, so git stash push is smarter.

eg:
git stash push -m "save only progress" progress.sh

git stash --keep-index

It stores the staged files and changed contents in the stash stack simultaneously.

$ git status
    modified:   progress.sh
    modified:   suffix.sh

$ git stash --keep-index
Saved working directory and index state WIP on master: ca052c9 Update README.md

$ git st
    modified:   progress.sh
    modified:   suffix.sh

git stash -u

-u means --include-untracked.
It supports to include files which are not tracked in the stash being created.

$ git st
    modified:   progress.sh
    modified:   suffix.sh

Untracked files:
    newfile

$ git stash -u
Saved working directory and index state WIP on master: ca052c9 Update README.md

$ git st
nothing to commit, working tree clean

git stash branch <branchName>

The command git stash branch support to create a new branch which contains the last commit and stashed contents, then it drops the stash if it applied successfully.
1. change files.
2. git stash
3. git stash branch <branchName>
4. review the change and commit to the new branch.
5. go back old branch, we can merge the new branch.

$ git stash push -m "save suffix.sh"
Saved working directory and index state On master: save suffix.sh

$ git stash branch test1
Switched to a new branch 'test1'
On branch test1
    modified:   suffix.sh

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (c73709950b50d1be86a9c6ff87a3ff1cbdf7cace)

Others

git stash all: it can remove everything from our working directory even if the files are not tracked.
git stash -p: --patch/-p can help us to include a part content in stash stack. Relevant article: Interesting Option -P For Git Command

Categories: Tool

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x