Stage 8 - Git History, Recovery and Advanced Tools
By Stage 7, review and merge are in place. The advanced part starts when something still goes wrong: maybe one commit introduced wrong behavior, or an unfinished idea is blocking a hotfix branch.

The difference between undo methods
In task-service, suppose feat: add export format contract file worked, but one commit in another branch broke existing behavior.
Two major approaches:
git revertadds a new commit that undoes the effects of a previous commit.git resetmoves your branch pointer back and rewrites local trajectory.
For shared branches, prefer revert:
git revert <commit-hash>
reset is usually for local cleanup before publishing:
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
Recovering after “I reset wrong”
git reflog tracks where HEAD moved recently:
git reflog
git switch -c recovery-branch <lost-commit-hash>
This can bring back commit references that seemed lost after pointer movement.
Stash for temporary suspension
Sometimes you need to interrupt current work to fix an urgent patch:
git stash push -m "WIP: task-service ordering tweak"
git switch main
git pull
git stash pop
Stash is a temporary shelf, not a long-term history plan.
Cherry-pick for surgical transfer
If one good fix exists in another branch and you only need that single change:
git cherry-pick <commit-hash>
This applies one commit without merging the full branch.
| Tool | Use case |
|---|---|
revert |
Undo published mistakes safely |
reset |
Fix local commit flow before push |
reflog |
Find recently moved references |
stash |
Hide unfinished work without creating a commit |
cherry-pick |
Move one commit across branches |
Use this stage to make recovery boring and predictable, not stressful.
Advanced discipline for team reliability
A practical rule: before using reset, ask whether the commit is already public. If yes, use revert so teammates are not surprised. If not public, reset can keep local history clean.
When you use stash, always apply it back from the same branch context. If your branch changed drastically while code is stashed, validate with git diff after stash pop and then create a new commit before switching again.
cherry-pick is a precision tool. It is powerful for hotfixes, and risky if overused because it can hide intent of an entire flow. Prefer it for single, verified commits and keep the rest as full merges.
Glossary
- version control
- A system for tracking project changes over time so developers can inspect, compare, and restore previous states.
- repository
- A storage area for a project, its files, history, and related metadata.
- commit
- A saved Git history point that records a related set of changes, the author, and the reason for the change.
- branch
- An independent line of work where changes can be developed without immediately affecting another line.
- merge
- The operation that combines changes from one branch or source into another.
- conflict
- A situation where a tool cannot automatically combine changes because different edits affect the same part.
- staging area
- The Git area where selected changes are prepared before they become part of the next commit.
- working tree
- The current files and folders checked out in your project directory, including uncommitted edits.
- diff
- A comparison that shows exactly which lines or values were added, removed, or changed.
- remote
- A named connection to a repository stored somewhere else, usually on a server such as GitHub.
- clone
- The operation that copies an existing repository from a remote location to your local machine.
- push
- The operation that sends local commits or changes to a remote repository.
- pull
- The operation that downloads changes from a remote repository and integrates them locally.
- pull request
- A review request that proposes merging one branch into another and gives teammates a place to discuss changes.
- fork
- A personal copy of another repository, usually used to propose changes without direct write access.
- review
- The engineering practice of checking changes for correctness, clarity, risks, and maintainability.
- rollback
- A deliberate return to an earlier safe state after a mistake, regression, or unwanted change.
- rebase
- A Git operation that moves commits to a new base commit, often used to make history more linear.
- tag
- A named marker pointing to a specific version, commit, image, or release artifact.