Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
878 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...