ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Revert in Git

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='15' AND `tutorial_submenu`='683' AND `tutorial_status`=1 LIMIT 1

Revert in Git

πŸš€ Git Revert: Undo Commits Without Losing History

git revert is used to undo a commit without deleting history. Unlike git reset --hard, it creates a new commit to reverse the changes.


πŸ“Œ When to Use git revert?

βœ… Safe for shared repositories (e.g., GitHub, GitLab, Bitbucket)
βœ… Does NOT delete commits but creates a new one to undo changes
βœ… Good for undoing specific commits without affecting others


1️⃣ Revert the Last Commit

git revert HEAD

➑ This reverses the last commit and creates a new commit.


2️⃣ Revert a Specific Commit

1️⃣ Find the commit hash:

git log --oneline

Example output:

a1b2c3d Fixed a bugf6g7h8i Added new feature

2️⃣ Revert that commit:

git revert a1b2c3d

➑ This creates a new commit that undoes only that commit, keeping others intact.


3️⃣ Revert Multiple Commits

git revert HEAD~2..HEAD

➑ This reverts the last two commits (HEAD to HEAD~2).


4️⃣ Revert Without Creating a Commit

If you don’t want an automatic commit, use:

git revert -n <commit-hash>

➑ Changes will be staged, and you can commit manually:

git commit -m "Reverted commit <hash>"


πŸ”₯ Example Workflow

git log --onelinegit revert f6g7h8i # Reverts "Added new feature"git push origin main


🎯 Summary

CommandEffect
git revert HEADUndo last commit (creates new commit)
git revert <commit-hash>Undo specific commit
git revert HEAD~2..HEADUndo last two commits
git revert -n <commit-hash>Revert without committing

πŸ’‘ Use git revert instead of git reset --hard for safe changes in shared repositories.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql