Wednesday, February 12, 2025

How to handle when code push accidently in deleted branch

Have you ever pushed your code, only to realize the branch was deleted? ๐Ÿ˜ฑ No worries—your work isn't lost! Git keeps a history of all commits, and you can easily recover your code.
๐Ÿš€ Steps to Recover Your Deleted Branch
1️⃣ Check Your Git Log Even if a branch is deleted, the commits still exist. Run:

Code Snippet

This will show a list of commit hashes with their messages.
2️⃣ Find Your Last Commit Look for the commit related to your deleted branch
3️⃣ Restore Your Branch Once you have the commit hash, recreate the branch:

Code Snippet

Note : Instead of "abc1234" write "your hashcode" and "recovered-branch" write your "new branch name"

๐Ÿ˜ŠNow you can push your code in that branch and you can able to create PR.๐Ÿ˜Š

No comments:

Post a Comment

How to make Scheduler with Azure Queue using .net

I created Two methods one for schedule and log in db and second method is related to reschedule message. 1. Schedule and Reschedu...