How to REVERT a Commit from GitHub in VS Code | Undo Git Commits Easily

Publicado em: 04 Março 2025
no canal de: ProgrammingKnowledge
12,396
42

*Accidentally made a wrong commit on GitHub? No worries!*

In this step-by-step tutorial, I’ll show you **how to revert a commit from GitHub using VS Code**. Whether you need to undo a commit before pushing or after pushing, this guide will help you fix mistakes safely!

---

*🔹 What You’ll Learn:*
✅ How to *revert a commit before pushing*
✅ How to *undo a commit after pushing to GitHub*
✅ How to *use Git reset and revert in VS Code’s terminal*
✅ How to *remove a commit from GitHub safely*
✅ How to *revert changes using VS Code’s Source Control*

---

*🔹 Prerequisites:*
✔️ *Visual Studio Code Installed* ([Download here](https://code.visualstudio.com/))
✔️ *Git Installed on Your System* ([Download here](https://git-scm.com/))
✔️ *A GitHub Repository to Work With*

---

*Step 1: Open the Repository in VS Code*

1️⃣ Open *VS Code* and navigate to your project folder
2️⃣ Open the *Terminal* (View → Terminal)
3️⃣ Check your commit history:
```bash
git log --oneline
```

---

*Step 2: Undo the Last Commit Before Pushing*

If you haven’t pushed the commit yet, you can *soft reset* it:

```bash
git reset --soft HEAD~1
```

🔹 This removes the commit but **keeps your changes**, so you can modify and recommit them.

---

*Step 3: Undo a Commit and Remove Changes (Before Pushing)*

If you want to *completely remove* the commit and changes, use:

```bash
git reset --hard HEAD~1
```

🚨 *Warning:* This will **delete your changes permanently**!

---

*Step 4: Revert a Commit After Pushing to GitHub*

If you already **pushed the commit to GitHub**, do the following:

🔹 *Revert the commit safely using `git revert`*

```bash
git revert commit-hash
```

🔹 This creates a **new commit that undoes the previous one**, keeping a clean history.

🔹 Push the revert commit to GitHub:
```bash
git push origin main
```

---

*Step 5: Use VS Code’s Source Control Panel*

1️⃣ Open the *Source Control* panel (Ctrl + Shift + G)
2️⃣ Right-click on the commit you want to undo
3️⃣ Select *"Revert Commit"* (if available)
4️⃣ Push the changes back to GitHub

---

*Step 6: Remove a Pushed Commit (Force Push Method)*

If you want to completely remove a commit from GitHub:
```bash
git reset --hard HEAD~1
git push --force
```

🚨 *Warning:* Force pushing rewrites history, which can cause issues if working in a team!

---

*Step 7: Reset to a Specific Commit*

If you need to **go back to an older commit**, first find the commit hash:
```bash
git log --oneline
```

Then reset to that commit:
```bash
git reset --hard commit-hash
git push --force
```

---

*Next Steps:*
📌 *How to Use Git & GitHub in VS Code* → [Watch Now]
📌 *How to Create a GitHub Pull Request* → [Watch Now]
📌 *Advanced Git Commands for Developers* → [Watch Now]

---

*👍 Like, Share & Subscribe!*
If this tutorial helped you, *LIKE**, **SHARE**, and **SUBSCRIBE* for more Git & GitHub tutorials!

💬 Have questions? Drop them in the *comments* below!

---

*🔹 Hashtags:*
#Git #GitHub #GitRevert #GitReset #UndoCommit #GitHubTutorial #VSCode #VersionControl #SoftwareDevelopment


Nesta página do site você pode assistir ao vídeo on-line How to REVERT a Commit from GitHub in VS Code | Undo Git Commits Easily duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário ProgrammingKnowledge 04 Março 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 12,396 vezes e gostou 42 espectadores. Boa visualização!