Git Areas and Stashing
Posted on August 28, 2020 in Git by Matt Jennings
The information below is from Git Foundations chapter of Git In-depth.
Three Areas Where Code Lives
- Work Area (Work Tree)
- Staging Area (Cache or Index)
- Repository
The Working Area
Called untracked files.
The Staging Area (Index or Cache)
- Files that are going to be part of the next commit.
- The staging area is how git knows what will change between the current commit and the next commit.
- To view files that are in the staging area:
git ls-files -s - Add a file to the next commit:
git add <file_name> - Delete a file in the next next commit:
git rm <file_name> - Rename a file in the next commit:
git mv <file_name>
The Repository
- The files git knows about.
- Contains all of your commits.
git add -p
- Allows you to stage commits in hunks interactively.
Git Stash
- Save un-commited work.
- The stash is safe from destructive operations.
- Stash changes:
git stash - List changes in a stash that are un-commited work
git stash list - Keep untracked files
git stash --include-untracked - Remove the last stash and apply those changes, unless there’s a merge conflict:
git stash pop - Remove the last stash
git stash drop - Remove all stashes
git stash clear
Git Stash – What Nina Uses
- Keep untracked files
git stash --include-untracked - Name stashes for easy reference
git stash save "WIP: making progress on foo" - Checkout the latest stash
git stash apply stash@{0}
or
git stash apply