Stash#
It’s common case when you need to switch to anoter branch during work. So you have to somehow save changes on the current branch. Of course you can commit change, but it’s not really good to create commit while some stage wasn’t finished.
For such cases there is a special tool called git stash
. You can store the state of your project and use it when you need it.
The following example shows that a file added to stage can be removed from the project and put into stash - it didn’t show up on the ls
output. But then we used the git stash apply
command to put the file back into the repository.
%%bash
mkdir stash_temp
cd stash_temp
git init &> /dev/null
echo "some content" > file
git add file
git commit -m "initial commit" &> /dev/null
echo "=====just created file2====="
echo "some content" > file2
ls
echo "=====now stashing====="
git add file2
git stash
ls
echo "=====stash apply====="
git stash apply
ls
cd ..
rm -r stash_temp
=====just created file2=====
file
file2
=====now stashing=====
Saved working directory and index state WIP on master: de96025 initial commit
file
=====stash apply=====
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: file2
file
file2