2 Ways to save your life when you confused push any code or file to your branch.

Way 1

1. Find your committed hash by :

git log

2. After found your commit hash you need revert it by :

git revert <commit-hash>

3. choose one at bellow with responsibility:

🟢 Uncomm…


This content originally appeared on DEV Community and was authored by Pheak Pheasa

Way 1

1. Find your committed hash by :

git log

2. After found your commit hash you need revert it by :

git revert <commit-hash>

3. choose one at bellow with responsibility:

🟢 Uncommit last commit (keep files):

git reset --soft HEAD~1

✅ Files stay staged, just remove commit.

🟡 Uncommit & Unstage (keep changes in working directory):

git reset --mixed HEAD~1

✅ Files stay, but unstaged (not in commit).

🔴 Uncommit & Remove changes:

git reset --hard HEAD~1

⚠️ Files & commit both gone! Careful!

🟣 Uncommit pushed commit (force push):

git reset --soft HEAD~1
git push --force

✅ Removes commit on remote branch too.

Way 2 in next post.


This content originally appeared on DEV Community and was authored by Pheak Pheasa


Print Share Comment Cite Upload Translate Updates
APA

Pheak Pheasa | Sciencx (2025-03-24T04:10:10+00:00) 2 Ways to save your life when you confused push any code or file to your branch.. Retrieved from https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/

MLA
" » 2 Ways to save your life when you confused push any code or file to your branch.." Pheak Pheasa | Sciencx - Monday March 24, 2025, https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/
HARVARD
Pheak Pheasa | Sciencx Monday March 24, 2025 » 2 Ways to save your life when you confused push any code or file to your branch.., viewed ,<https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/>
VANCOUVER
Pheak Pheasa | Sciencx - » 2 Ways to save your life when you confused push any code or file to your branch.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/
CHICAGO
" » 2 Ways to save your life when you confused push any code or file to your branch.." Pheak Pheasa | Sciencx - Accessed . https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/
IEEE
" » 2 Ways to save your life when you confused push any code or file to your branch.." Pheak Pheasa | Sciencx [Online]. Available: https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/. [Accessed: ]
rf:citation
» 2 Ways to save your life when you confused push any code or file to your branch. | Pheak Pheasa | Sciencx | https://www.scien.cx/2025/03/24/2-ways-to-save-your-life-when-you-confused-push-any-code-or-file-to-your-branch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.