Stash, Cherry-Pick, Tags, and Releases
Learn practical tools for temporarily shelving work, selectively transferring commits, marking releases, and managing versions.
Temporarily Stashing Work
git stash temporarily saves working-tree and staging changes so you can switch context without committing incomplete work. A stash is stored in Git's stash references and can later be applied or popped.
Modern Git also supports git stash push -m for descriptive stash messages and git stash push -u to include untracked files.
git stash push -m "WIP login validation"
git switch main
git switch feature/login
git stash list
git stash popstash push saves the changes. stash list shows saved entries, while stash pop applies the latest stash and removes it if successful.- Stash is useful for temporarily incomplete work.
- Use descriptive stash messages when maintaining multiple entries.
- Stashes can conflict when applied to changed code.
What is the primary purpose of `git stash`?
Cherry-Picking Commits
git cherry-pick applies the changes introduced by selected commits onto the current branch. It is useful when one specific fix is needed without merging an entire branch.
Cherry-picking creates a new commit on the destination branch, so the resulting commit normally has a different hash from the original.
git switch release/1.4
git cherry-pick abc1234abc1234 to the current branch and creates a new commit containing those changes.- Cherry-pick is useful for selective commit transfer.
- The resulting commit is normally a new commit with a different hash.
- Cherry-picking can introduce conflicts.
What does cherry-pick primarily do?
Advanced History Inspection
Git history can be queried in many ways. git log --author, --grep, --since, path filters, and graph formatting allow you to locate specific changes. git blame identifies the commit associated with each line of a file and can be useful when investigating historical decisions.
git blame is most useful for finding the commit and author associated with a line so you can inspect the surrounding historical context.
git log --oneline --all --grep="authentication"
git log --author="Suriya" --oneline
git log -- src/auth.js
git blame src/auth.js- Git log can filter history by author, message, date, and path.
git blameis a historical attribution tool.- Inspect the associated commit to understand why a line was introduced.
What is `git blame` primarily used for?