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

Veröffentlicht am: 04 März 2025
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video How to REVERT a Commit from GitHub in VS Code | Undo Git Commits Easily mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ProgrammingKnowledge 04 März 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 12,396 Mal angesehen und es wurde von 42 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!