Git 2 reference · Undoing Changes
git revert Command (Git)
Create a new commit that undoes an earlier commit's changes; the safe way to undo commits that were already pushed.
Git 2
Syntax
git revert [--no-edit] COMMIT
Parameters
| Parameter | Description |
|---|---|
--no-edit |
Use the default message. |
-m 1 |
Revert a merge commit, keeping parent 1. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'discount=50' > promo.txt; git add .; git commit -q -m 'Add 50% promo'
git revert -q --no-edit HEAD
git log --oneline; ls
Output
302f114 Add 50% promo 7f7f133 Initial commit README.md promo.txt
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo a > a.txt; git add .; git commit -q -m 'Add a'
echo b > b.txt; git add .; git commit -q -m 'Add b'
git revert -q --no-edit HEAD~1
ls
Output
README.md a.txt b.txt
Run this on your computer — see “Get Started” for setup.
Related
git reset· Move the current branch to another commit, keeping changes staged (--soft), unstaged (default) or discarding them (--hard).git cherry-pick· Apply the changes of specific commits from another branch onto the current branch as new commits.- Undoing Changes · tutorial