Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pull down a commit from Github (Enterprise) that I don't have locally?

Tags:

git

github

I accidentally did a push --force on the wrong repo (too many termminals open), effectively resetting the master branch back to an earlier commit.

Looking at my build system I can see that the commit used to point to XYZ, however I don't have that commit locally as I hadn't done a pull or fetch recently. The repo is in Github, and I can navigate in Github to view the commit, so I know it is there.

How can I pull down the commit so I can reset master back to the right commit without having to bother the dev who pushed that change?

like image 638
checketts Avatar asked Jan 05 '16 18:01

checketts


People also ask

How do I go to a specific commit in GitHub?

On the main GitHub page of the project click on NNN commits in the top left. You can see the list of commits from the most recent at the top, to older commits below that. You can scroll down and click on "Older" to see older commits.

Why my commit is not showing in GitHub?

Commits must be made with an email address that is connected to your account on GitHub.com, or the GitHub-provided noreply email address provided to you in your email settings, in order to appear on your contributions graph.

How do I run GitHub code after cloning?

From your repository page on GitHub, click the green button labeled Clone or download, and in the “Clone with HTTPs” section, copy the URL for your repository. Next, on your local machine, open your bash shell and change your current working directory to the location where you would like to clone your repository.


1 Answers

You can create a branch from an orphaned commit in the Github GUI by doing the following:

  1. Browse to https://github.com/yourOrg/yourRepo/tree/commitHash
  2. Click on the branch dropdown
  3. Type in the new branch name and hit Enter

Now that you have a branch, you can use your Git client to check it out as normal.

Github create branch drop down

Notes

This post was helpful as I researched this. It basically states that you are stuck unless you have a local repository containing the orphaned commits. My approach allows you to add a branch so the commit is no longer orphaned.

like image 93
westse Avatar answered Sep 28 '22 08:09

westse