Coding/Learn/git/git stash and history log
Git & GitHub Complete Course
01.Introduction, Architecture & Configuration
02.Staging Area, atomic Commits & git status
03.Branching, Fast-Forward & 3-Way Merging
04.Stash, Log Visualization & History Inspection
05.Workflows (Git Flow, Trunk-Based) & Semantic Tagging
06.SSH Keys, Remote Repositories & Origin Setup
07.Push, Fetch, Pull & Upstream Tracking Branches
08.Forking, Clones & Open-Source Pull Requests (PRs)
09.GitHub Flow, Branch Protection & GitHub Pages
10.Undoing Changes: git restore & Safe Public git revert
11.Reset: Deep Dive into --soft, --mixed & --hard
12.Commit Amending & Interactive Rebase (git rebase -i)
13.Reflog & Disaster Recovery (Reviving "Lost" Commits)
14.Merge Conflicts Resolution & git rerere
15..gitignore Rules & .gitattributes Cross-Platform Handling
16.Hooks & Automated Quality Assurance (Pre-Commit)
17.Submodules & Large File Storage (Git LFS)
18.GPG Cryptographic Signing & git cherry-pick
19.Advanced Remotes, Garbage Collection (git gc) & Maintenance
20.Capstone: Production Multi-Branch Enterprise Release Pipeline
Course Certificate0%

Complete all lessons to earn

LearnGit Stash, Log Visualization & History Inspection
4 / 20 0%
Lesson 04 of 20
6 mins read

Git Stash, Log Visualization & History Inspection

PreviousNext Lesson
In Plain English

git stash temporarily shelves uncommitted modifications so you can switch branches to fix urgent bugs without making dirty WIP commits. Format git log graphs to trace ancestry, branch divergences, and commit authors.

The Mental Model

"Git stash is a temporary drawer: you sweep your half-finished blueprints off your desk into the drawer, attend to an urgent customer request, and then pull your blueprints back out onto the desk."

Deep Dive: How It Works

git stash push -m "work": Stores staged and unstaged changes onto a LIFO stack.

git stash pop: Re-applies the most recent stash onto the current working directory and removes it from the stash list.

Formatted Log Graph: git log --graph --oneline --all provides an ASCII visual map of all branches.

Syntax Blueprint

git stash push -m "WIP on parser"
git switch hotfix
# Fix bug & commit
git switch feature
git stash pop

Stash active uncommitted changes, switch branches, and pop stash back when returning.

PointCore Rules to Remember

Point star
Include Untracked Files: Use git stash -u (or --include-untracked) to stash new files not yet tracked by git.
Point star
Inspecting Stash Contents: git stash show -p stash@{0} displays full line diffs stored inside a stash.
Point star
Compact Log History: git log --oneline --decorate displays concise commit hashes, branch pointers, and tags.

Common Beginner Traps & How to Fix Them

Mistake:Assuming git stash automatically stashes brand new untracked files.

Why it happens: By default, git stash only tracks files already known to the Git index.

How to fix: Always include the -u flag: git stash -u.

Pro Tip: Add an alias to your global git config for log graphs: git config --global alias.lg "log --graph --oneline --all --decorate".

Live Interactive Example

Hit Run Code to see it live
Stash and Pop Workflow
Git 2.45 / CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
Output Console
Click "Run Code" to view the rendered output.
How it works: git stash push cleans the working directory, and git stash pop restores the uncommitted changes.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Save Work with git stash

  • PointStash the uncommitted modification with "git stash push -m "save work"".
  • PointVerify the working directory is clean using "git status --short".
1
2
3
4
5
6
7
8
9
10
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates