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?
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.
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.
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.
You can create a branch from an orphaned commit in the Github GUI by doing the following:
Now that you have a branch, you can use your Git client to check it out as normal.
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.
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