How do you recover a deleted un-merged branch in your project source code?

Devops Devops in Devops . 3 years ago

  1   0   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

By default, git does not allow you to delete a branch whose work has not yet been MERGED into the main branch.

 To see the list of branches not merged with the CHECKED out branch run:

Divya1@Divya:initialRepo [master] $git branch --no-merged  DEV

 --If you TRY to delete this branch, git displays a warning:

Divya1@Divya:initialRepo [master] $git branch -d dev error: The branch 'dev' is not fully merged. If you are sure you want to delete it, run 'git branch -D dev'.

--If it is still deleted using the -D flag as:

Divya1@Divya:initialRepo [master] $git branch -D dev

--See the references log information

Divya1@Divya:initialRepo [master] $git reflog cb9da2b (HEAD -> master) HEAD@{0}: checkout: MOVING from dev to master b834dc2 (origin/master, origin/dev) HEAD@{1}: checkout: moving from master to dev cb9da2b (HEAD -> master) HEAD@{2}: checkout: moving from master to master cb9da2b (HEAD -> master) HEAD@{3}: checkout: moving from dev to master b834dc2 (origin/master, origin/dev) HEAD@{4}: checkout: moving from master to dev cb9da2b (HEAD -> master) HEAD@{5}: checkout: moving from uat to master 03224ed (uat) HEAD@{6}: checkout: moving from dev to uat

b834dc2 is the commit id when we jumped to ‘dev’ branch
Create a branch named ‘dev’ from this commit id again.

Divya1@Divya:initialRepo [master] $git checkout -b dev b834dc2 Switched to a new branch 'dev' Divya1@Divya:initialRepo [dev]

Posted on 31 May 2022, this text provides information on Devops related to Devops in Devops. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Tuteehub forum answer Answers

Post Answer

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.