Git allows to fetch from any given remote and reference, for example
git fetch <remote-url> <reference>
So that those given commits are available without having to add remotes or creating branches.
This however only works for references, like branch names or tags, but not for specific hashes and thus commits that are not referenced directly anywhere.
Is there a way to fetch a specific commit from a remote?
Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here . That will pull just this commit into your current branch.
To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.
First clone the latest repo from git (if haven't) using git clone <HTTPs link of the project> (or using SSH) then go to the desire branch using git checkout <branch name> . Now the particular commit will be available to your local. Change anything and push the code using git push origin <branch name> . That's all.
As today I tried:
git fetch origin <commit-hash>
And it works like a charm! (git version 2.20.1)
Just be sure the <commit-hash>
is the full length reference
See "Pull a specific commit from a remote git repository":
With Git 2.5 (July 2015), you will be able to do:
git fetch --depth=1 <a/remote/repo.git> <full-lenght SHA1> git cat-file commit $SHA1
If the SHA1 is "reachable" from one of the branch tips of the remote repo, then you can fetch it.
Caveats:
uploadpack.allowReachableSHA1InWant
config (and you need that config to be set to true
, in order to allow a single commit fetch).git rev-parse
, since you don't have all the commits, as noted by Jim Hurne in the comments.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