3

I have very limited bandwidth,so I was wondering if it whether it would be possible to get a commit from another repository without actually cloning it. The two repositories have the same file structure but they do not share history at all. Both of them are independent of each other but I still want to cherry-pick a commit from one of them to other. Is this possible ?

Abhishek Ranjan
  • 464
  • 3
  • 15
  • 2
    Possible duplicate of [Is it possible to cherry-pick a commit from another git repository?](http://stackoverflow.com/questions/5120038/is-it-possible-to-cherry-pick-a-commit-from-another-git-repository) – Tim Biegeleisen May 17 '16 at 06:58
  • @TimBiegeleisen The question there simply asks if it is possible to cherry-pick from other repository,However my question is to do the same without cloning the other repo.. – Abhishek Ranjan May 17 '16 at 07:07
  • And I believe that question gave an option for doing it without cloning the repo. – Tim Biegeleisen May 17 '16 at 07:07
  • Doesn't git fetch also clones the repo? – Abhishek Ranjan May 17 '16 at 07:11
  • see here, the fetch will have pulled down the remoteBranch and put it into a local branch called “remoteBranch”. creates a local copy of a remote branch which you shouldn’t manipulate directly; instead create a proper local branch and work on that. Taken from :https://blog.mikepearce.net/2010/05/18/the-difference-between-git-pull-git-fetch-and-git-clone-and-git-rebase/ – Abhishek Ranjan May 17 '16 at 07:14
  • When you say "Another" repository, does it mean a 2nd remote? – dubes May 17 '16 at 09:01
  • @dubes I am not talking branches,There is another kernel repo of some other device, and I want to cherry pick a few decent changes,Thats it. – Abhishek Ranjan May 17 '16 at 12:37

2 Answers2

3

Short answer: in theory possible, but not easy to do.

From "Retrieve specific commit from a remote Git repository", you would need:

  • git repo hosting server with:
    • git 2.5+
    • git config uploadpack.allowReachableSHA1InWant true (on the server side)
  • A shallow clone with single commit fetch (again, git 2.5+, client side)

That is: you would initialize an empty repo, add the url of the remote origin repo, and:

git fetch --depth=1 ../testrepo/.git <SHA1>

That would bring only one commit.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • what do you mean by "git repo hosting server " – Abhishek Ranjan May 17 '16 at 09:37
  • Yes, though you'd want to grab *two* commits if you intend to cherry-pick the difference between them. – torek May 17 '16 at 09:43
  • @AbhishekRanjan I mean you need a git on the server side (the server which is referenced by the remote repo url) which has the right version (2.5+) and config (`uploadpack.allowReachableSHA1InWan`) – VonC May 17 '16 at 10:22
  • @AbhishekRanjan "git repo hosting server ": the git which is on the remote server managing the bare repos that you are cloning. – VonC May 17 '16 at 10:27
  • oh in my case github is the server,that would work right? @VonC – Abhishek Ranjan May 17 '16 at 12:38
  • @AbhishekRanjan I don't think so: that config might not be active on their side. – VonC May 17 '16 at 13:02
0

You could just fetch the branch that has the commit from another git repo and then git cherry-pick it.

ElpieKay
  • 19,185
  • 5
  • 22
  • 36