Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Reset in Git

Reset in Git

🚀 Reset in Git: How to Undo Changes

In Git, reset is used to undo changes at different levels—unstaging files, removing commits, or resetting your working directory.


📌 Types of git reset and Their Uses

1️⃣ Soft Reset (--soft)

Keeps your changes & moves HEAD to a previous commit
Use when you want to change commit history but keep changes

git reset --soft HEAD~1

➡ Moves HEAD back one commit but keeps your changes staged.
➡ Now, you can edit and recommit:

git commit -m "Updated commit message"


2️⃣ Mixed Reset (Default)

Unstages changes but keeps the files
Use when you want to undo a commit but keep the changes

git reset HEAD~1

➡ Moves HEAD back one commit
➡ Your changes remain unstaged, so you can add them again with:

git add .git commit -m "New commit message"


3️⃣ Hard Reset (--hard)

🚨 WARNING: This permanently deletes commits and changes!
Use when you want to remove everything, including uncommitted changes

git reset --hard HEAD~1

➡ Moves HEAD back one commit
Deletes all changes permanently


🔥 Reset to a Specific Commit

Instead of HEAD~1, you can reset to a specific commit:

git reset --hard <commit-hash>

Find commit hashes with:

git log --oneline


🎯 Summary

CommandEffect
git reset --soft HEAD~1Undo commit but keep changes staged
git reset HEAD~1Undo commit & unstage changes
git reset --hard HEAD~1Deletes commit & changes 🚨
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