Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
875 views
in Technique[技术] by (71.8m points)

git - How to undelete a branch on github?

It seems that I delete a branch on github when I should not do it.

What I did was as follow:

1- I add a new .gitignore to my system

2- I use

 git rm -r --cached .  
 git add .  
 git commit -m ".gitignore is now working"  

When I did this, I had one branch on my local system but the server had two branch.

Then I pushed my branches to server and since I had not the second branch, the second branch was deleted on server.

How can I bring it back?

I am using Github as remote server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you know the last commit message of the deleted branch you can do this:

git reflog

# search for message

fd0e4da HEAD@{14}: commit: This is the commit message I want

# checkout revision

git checkout fd0e4da 

or

git checkout HEAD@{14}

# create branch

git branch my-recovered-branch

# push branch

git push origin my-recovered-branch:my-recovered-branch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...