Summary - Revert
- Git course
- Intermediate
- Lesson 40/82
- 5 min
Combine the revert flow to safely undo changes.
Safe undo workflow summary
git revert creates a new commit that inverts the changes brought by an erroneous or unwanted commit. Unlike git reset which winds history backwards, revert is safe on shared branches because it does not erase past commits. It can target a single commit and is controlled with --continue or --abort when conflicts arise.
git revert --no-edit HEAD
git revert --no-edit <hash>
git log --onelineThis workflow ensures you maintain a transparent and clean audit trail while collaborating in teams.
Practice Complete and verify revert flow
Revert the latest commit with git revert --no-edit -q HEAD, print file content using cat surum.txt, and display the new commit subject with git log -1 --format="%s".
Starter code
git init -q -b main
git config user.name "Derya"
git config user.email "derya@example.com"
echo "v1.0" > surum.txt
git add surum.txt
git commit -qm "v1.0 yayinlandi"
echo "hatali ozellik" >> surum.txt
git commit -am -q "Hatali ozellik"
# Son commit'i revert et, surum.txt icerigini ve son basligi basSample solution
git init -q -b main
git config user.name "Derya"
git config user.email "derya@example.com"
echo "v1.0" > surum.txt
git add surum.txt
git commit -qm "v1.0 yayinlandi"
echo "hatali ozellik" >> surum.txt
git commit -am -q "Hatali ozellik"
git revert --no-edit -q HEAD
cat surum.txt
git log -1 --format="%s"Expected output
v1.0 Revert "Hatali ozellik"
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the primary characteristic that distinguishes git revert from git reset?
- Only changing the author email while preserving files
- Only clearing changes that are not yet staged
- Deleting all branches in the repo with a single command
- Creating a forward inverse commit instead of deleting history Correct answer
Explanation: git revert does not rewrite history; it safely undoes work by adding a new commit that is the inverse of an earlier commit.
2 Create inverse commit
git ____ --no-edit HEAD
git revert --no-edit HEAD
Explanation: git revert --no-edit HEAD creates a new commit that inverts the latest commit.
3 Revert workflow matching
| Term | Meaning |
|---|---|
İleriye dönük kayıt |
Creates inverse commit without delete |
Paylaşılan dallar |
Safe undo in teamwork |
Otomatik mesaj |
Git generates the revert title |
Geri alma iptali |
abort returns to state before revert |