What is Git Stash means?
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).
To demonstrate stashing, you should go into your project and start working on a couple of file(s) and possibly stage one of the changes.
Power of git stash
Why do we need git stashing?
We have already git commit command right then why stashing? You can commit your code and switch to another branch. Your actual work is in a "messy state" and there are still more new feature changes need to be done on the projects coming up and don't want to commit your current changes.
For this problem, a simple solution is that you can use the command git stash.
You are working on a feature branch let's say feature1. But there is a burning issues in live needs higph priority on the hotfix, you are the only person can fix it. In such situations stashing the current changes and working highly urgent task once it is commited then we can get back to last changes. Stashing is temporary store in git repository without disturbing index, stage, work areas.
1. Create a directory name as 'git-stashtest'
2. initialize the git initial repo
clear mkdir git-stashtest; cd git-stashtest; ls -lrt # Do the changes like create/modify a fileYou got the eligibility to play with git stash command
How to use the git stash command?
The "git stash" command can help you to (temporarily but safely) store your uncommitted local changes - and leave you with a clean working copy. Stash changes in a dirty working directory
Example: Enter the data in the 'index.html file and stash the changes.
Introduces the option of stashing selected pathspecs. git stash save : The changes can be saved with or without message.
git stash list : To check the stored stashes. You can list the stashes by using this command.
git stash show : We can track the stashes and their changes. To see the changes in the file before stash and after stash operation.
Git stash with list
vi index.html # working with edit git stash cat index.html
example of git stash |
Git push
Introduces the option of stashing selected pathspecs. git stash save : The changes can be saved with or without message.
git stash list : To check the stored stashes. You can list the stashes by using this command.
git stash show : We can track the stashes and their changes. To see the changes in the file before stash and after stash operation.
Git stash apply
Example for git stash apply |
Git stash with list
Git stash pop
Git stash pop with index
Git stash drop with index number
You can clear specific stashed index as shown below:
git stash list git stash drop 2 git stash list
How to clear up the stashed dirty?
Git stash Clear
git stash list git stash clear # clears here git stash list # to check the clear doneremove all stashed entries
Example :
git stash clear
Happy to share new learnings on GitOps. If you find this useful please share it to your technical communities.
No comments:
Post a Comment