Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover a commit sent as a pull-request from a deleted fork on GitHub

Tags:

git

github

I did something stupid…

  1. I fork­ed a repo on GitHub.
  2. I made some changes, commit­ted them on my fork.
  3. I sent this commit as a pull-request back to the original repo.
  4. Here comes the stupid part: I delete­d my fork.

The owner of the original repo requested a couple changes in my code before he could accept the pull-request, which I'd gladly do.

I tried re-forking the repo, but I can't checkout the commit from the pull-request, it's not even there as an "unlinked" commit (a commit that is not part of any branch or tag, I don't know the official terminology).

My question is: How can I recover the commit sent as a pull-request ?

If there's no way, re-doing the changes in a new commit is an option, but the pull-request would be lost. My question is not about not losing the changes from the commit, it's about not losing the git history, meaning keeping the commit's SHA1 (and anything else I might not be aware of).

like image 397
1ace Avatar asked Jan 07 '14 17:01

1ace


People also ask

How do I recover a deleted pull request?

Restoring a deleted branchUnder your repository name, click Pull requests. Click Closed to see a list of closed pull requests. In the list of pull requests, click the pull request that's associated with the branch that you want to restore. Near the bottom of the pull request, click Restore branch.

What happens to pull request when branch is deleted?

Previously, GitHub's web UI did not allow deleting a branch that was associated with an open pull request. Now you can delete such a branch from the UI. However, doing so will close all open pull requests associated with the branch. Before the branch is deleted, you must confirm that the pull requests may be closed.

How do I reopen a closed pull request on GitHub?

You need the rights to reopen pull requests on the repository. The pull request hasn't been merged, just closed. Go to Pull requests add filter `is:closed` choose PR you want to reopen. Select from checkbox and mark as Open.


1 Answers

It is possible to fetch pull requests to your local machine.

Without having a link to the pull request in question it's hard to test whether this will work, but you can try to

  1. create a new fork of the repository,
  2. clone your new fork,
  3. fetch your pull request from the upstream repository,

    git remote add upstream https://github.com/User/repository.git
    
    $EDITOR .git/config
    # Add `fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*` to
    # the relevant section, as outlined in the linked page. Note that
    # we use `upstream` instead of `origin` as the target.
    
    git fetch upstream
    
  4. merge the pull request into your local repository, e.g.

    git checkout master
    git merge --ff-only upstream/pr/1
    
  5. and then push it back to your new fork.

If that fails, you can submit a support request to GitHub asking them to restore your repository. From an FAQ about security:

We do not retroactively remove repositories from backups when deleted by the user, as we may need to restore the repository for the user if it was removed accidentally.

To initiate this process, contact their support team as soon as possible.

like image 180
Chris Avatar answered Oct 30 '22 07:10

Chris