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.
A deleted Git branch can be restored at any time, regardless of when it was deleted. Open your repo on the web and select the Branches view. Search for the exact branch name using the Search all branches box in the upper right. Click the link to Search for exact match in deleted branches.
If you have deleted the file and already committed the changes, you need to use the ` git checkout` command to restore the file. First, you need to find out the checksum of the commit that deleted the file, and then check out the file from the previous commit.
I asked GitHub Support, this was their response (emphasis mine): We use a separate ref namespace for all Pull Requests which we use for various things including restoring the branch. Since we keep those [Pull Request] refs indefinitely, there's no time limit on restoring a branch.
In Git, branches are just pointers (references) to commits in a directed acyclic graph (DAG) of commits. This means that deleting a branch removes only references to commits, which might make some commits in the DAG unreachable, thus invisible.
I am using Github as remote server. If you know the last commit message of the deleted branch you can do this: If this branch was deleted during the Pull Request, you can undo that right there in the UI using the "restore branch" button.
Local branches are branches on your local machine and do not affect any remote branches. The command to delete a local branch in Git is: git branch is the command to delete a branch locally. -d is a flag, an option to the command, and it's an alias for --delete.
If this branch was deleted during the Pull Request, you can undo that right there in the UI using the "restore branch" button. Tricky part is actually finding a PR that has been merged and closed, you just need to know the URL or the PR number to put into the URL.
There is no retention policy on deleted branches. A deleted Git branch can be restored at any time, regardless of when it was deleted. Open your repo on the web and select the Branches view. Search for the exact branch name using the Search all branches box in the upper right. Click the link to Search for exact match in deleted branches .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With