Git - Part 7: Stash away changes
Stash away changes
git stash
Check stash list
git stash list
Apply the most recent stash and leave it on the list
git stash apply
Apply specific stash and leave it on the list
git stash apply stash@{0}
Apply the most recent stash and clear it from the list
git stash pop
Apply specific stash and clear it from the list
git stash pop stash@{0}
Delete the most recent stash from the list
git stash drop
Delete specific stash from the list
git stash drop stash@{0}
Apply stash to a new branch called feature
git stash branch feature
Exercise
- Create index.html file with content <h1>Hello World!</h1> and blank test.html file
touch index.html
vi index.html
touch test.html
- Add all to staging area and commit to master branch
git add .
git commit -m "Initial commit"
- Create new branch named 'feature-branch'
git checkout -b feature-branch
- Edit file test.html and add content <h2>This is a test</h2>
vi test.html
- Stash the changes
git stash
- Checkout master branch
git checkout master
- Edit file index.html and change <h1> tags to <h3> tags
vi index.html
- Add and commit changes
git add .
git commit -m "Change header tags"
- Checkout branch feature-branch
git checkout feature-branch
- Check stash list
git stash list
- Apply stash with 'pop' command
git stash pop
- Add and commit changes to feature-branch
git add .
git commit -m "Changes applied"
- Checkout master branch and merge feature-branch
git checkout master
git merge feature-branch