Git Stash Changes
This option used to stash the changes in the current working directory away.
Syntax:
git stash [option]
Example:
Check the current status of files in your project using git status command. Below output showing that one file is modified and 2 files are newly added.
rahul@tecadmin:/app$ git status -s M users.txt ?? config.php ?? login.html
Run git stash in your project. This will current working directory and index state. You can again run git status and you will find that the modified file is missing from the list.
rahul@tecadmin:/app$git stash Saved working directory and index state WIP on master: b62a88d Update README.md HEAD is now at b62a88d Update README.md rahul@tecadmin:/app$git status -s ?? config.php ?? login.html
let’s recover your stashed files in your project. First, check the list if stash with there id. Now run “git stash pop” to restore last stashed version.
rahul@tecadmin:/app$git stash list stash@{0}: WIP on master: b62a88d Update README.md rahul@tecadmin:/app$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)
Again check the status, you will find the modified file is again showing in list.
rahul@tecadmin:/app$git status -s M users.txt ?? config.php ?? login.html