GIT

Git Stash

Basically, git stash saves your uncommitted changes locally, this command issued to store your uncommitted local changes temporarily. If you want learn about git read this tutorial.

Example

Before using this command  first check the current status of the file in your current project. Follow the below command and in the output  you will see that one file is modified and 2 file are added.

$ git status -s 

S users.txt
?? config.php
?? login.html

Now execute this below command again in your project and index state. Now again run the below command and you will get the modified file is missing from the list.

$ git stash 

Saved working directory and index state WIP on master: b62a88d Update README.md
HEAD is now at b62a88d Update README.md

$ git status -s 

?? config.php
?? login.html

If you want to recover your stashed file from your project, first of all you have to check the list of stash with the ID and run the (#git stash pop) command to restore latest stashed version.

$ git stash list
stash@{0}: WIP on master: b62a88d Update README.md
$ git stash pop
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

modified: users.txt

Untracked files:
(use "git add ..." to include in what will be committed)

config.php
login.html

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

Lets again run the #git status -s command and you will find the modified file again.

$ git status -s 

 S users.txt
?? config.php
?? login.html

FAQs

Question 1 : What is git stash?

Answer : Basically, this command saves your uncommitted changes locally. To create a stashed simply run the this command without any arguments.

Question 2 : Why we use git stash?

Answer : If you want to save your changes temporarily in working directory you can use git stash. After that you can quickly switch contexts when they are not ready  to commit changes.

Question 3 : How to check my git stashed file?

Answer : To find the git stashed file simply run the git stash list command. This command will list all your stashed and corresponding  stash index.

Question 4 : What is git rebase?

Answer : Basically, git rebase is a command use by developers to integrate changes from one branch to another branch.

Question 5 : Can we git stash a single file?

Answer : Yes, if you want to git stash a single file just mention the path of the file along with #git stash push command.

 

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment