Summary### SummarySummarySummary
This issue documents several advanced Git commands and practical usage examples so contributors can quickly reference how to use them: git stash, git cherry-pick, git revert, and git reset. Each section includes a concise explanation, common options, safety notes, and copy‑paste examples.
Scope
- Audience: contributors and maintainers who need a quick reference for advanced Git workflows.
- Goal: make it safe and easy to apply, revert, or move commits and manage local work in progress.
Content
- git stash
What it does
- Temporarily saves uncommitted changes (working tree and index) so you can switch branches or pull without committing unfinished work.
Common commands
- Save changes:
- git stash push -m "WIP: "
- List stashes:
- Apply stash (keep entry):
- git stash apply stash@{0}
- Apply and remove:
- Show stash diff:
- git stash show -p stash@{0}
- Drop a stash:
- Create a branch from stash:
- git stash branch feature-from-stash stash@{0}
Safety notes
- Use descriptive messages with -m when you have multiple WIPs.
- git stash pop removes the stash even if apply fails; use git stash apply to keep it until successful.
- git cherry-pick
What it does
- Copies the changes introduced by an existing commit (or commits) onto your current branch as new commits.
Common commands
- Pick a single commit:
- Pick multiple commits:
- git cherry-pick sha1 sha2 sha3
- Pick a range (inclusive):
- git cherry-pick shaA..shaB
- Add original commit reference in message:
- Apply without committing (stage changes only):
Safety notes
- Cherry-picking may cause conflicts; resolve them and run git cherry-pick --continue.
- Use -x for traceability when bringing commits between branches.
- git revert
What it does
- Creates a new commit that undoes the changes from a specified commit. Safe for public branches because it preserves history.
Common commands
- Revert a single commit:
- Revert multiple commits (newer to older):
- git revert sha_newer sha_older
- Revert without editor:
Safety notes
- git revert appends a new commit that negates the target commit; resolve conflicts and run git revert --continue if needed.
- git reset
What it does
- Moves HEAD to a specified commit and optionally updates the index and working tree. It can rewrite history—use with caution on shared branches.
Modes and examples
- Soft (move HEAD, keep index & working tree — changes staged):
- Mixed (default — move HEAD, reset index, keep working tree — changes unstaged):
- Hard (move HEAD, reset index & working tree — discards changes):
Other examples
- Unstage a file but keep changes:
- git reset HEAD -- path/to/file
- Reset to remote branch state (dangerous):
- git fetch origin
- git reset --hard origin/main
Safety notes
- Avoid git reset --hard on shared branches; prefer git revert for undoing public commits.
Quick reference
- Keep local WIP while switching tasks: git stash
- Bring a commit from another branch: git cherry-pick
- Safely undo a public commit: git revert
- Rewrite history / move HEAD locally: git reset
Examples (copy/paste)
Stash, switch branch, apply stash
git stash push -m "WIP: tweak formatting"
git checkout other-branch
do work, then return
git checkout feature-branch
git stash pop
Cherry-pick a commit from another branch
git checkout feature-branch
git cherry-pick abc123 # abc123 is commit SHA from another branch
Revert a public commit
git checkout main
git pull
git revert abc123
git push
Reset local branch to drop last commit (keep changes staged)
git reset --soft HEAD~1
Notes about repository and metadata
- Repository: youthlin/t
- Suggested label(s): documentation
If you want,
Summary###SummarySummarySummaryThis issue documents several advanced Git commands and practical usage examples so contributors can quickly reference how to use them: git stash, git cherry-pick, git revert, and git reset. Each section includes a concise explanation, common options, safety notes, and copy‑paste examples.
Scope
Content
What it does
Common commands
Safety notes
What it does
Common commands
Safety notes
What it does
Common commands
Safety notes
What it does
Modes and examples
Other examples
Safety notes
Quick reference
Examples (copy/paste)
Stash, switch branch, apply stash
git stash push -m "WIP: tweak formatting"
git checkout other-branch
do work, then return
git checkout feature-branch
git stash pop
Cherry-pick a commit from another branch
git checkout feature-branch
git cherry-pick abc123 # abc123 is commit SHA from another branch
Revert a public commit
git checkout main
git pull
git revert abc123
git push
Reset local branch to drop last commit (keep changes staged)
git reset --soft HEAD~1
Notes about repository and metadata
If you want,