======================================================
> git --version
git version 2.10.2
> git clone
https://github.com/chalstrick/dondalfi.git
Cloning into 'dondalfi'...
...
> git clone
https://github.com/chalstrick/dondalfi.git dondalfi2
Cloning into 'dondalfi2'...
...
> cd dondalfi
> touch b
> git add b
> git commit -m add_b
[master a29d652] add_b
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b
> echo 2 >b
> git commit –a -m mod_b
[master 17b07fd] mod_b
1 file changed, 1 insertion(+)
> git log -2
commit 17b07fdb4c177d40a9b09b9cf012581b07d3f53d
Author: Christian Halstrick <christian.halstrick@xxxxxxx>
Date: Mon Feb 13 10:08:41 2017 +0100
mod_b
commit a29d652966d835393dfc98e7d266d1e4c8d184f7
Author: Christian Halstrick <christian.halstrick@xxxxxxx>
Date: Mon Feb 13 10:08:13 2017 +0100
add_b
> git push origin HEAD:testFetch
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 504 bytes | 0 bytes/s, done.
Total 6 (delta 2), reused 2 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 1 local objects.
To
https://github.com/chalstrick/dondalfi.git
* [new branch] HEAD -> testFetch
> cd ../dondalfi2/
> git fetch origin a29d652966d835393dfc98e7d266d1e4c8d184f7:newBranch
error: no such remote ref a29d652966d835393dfc98e7d266d1e4c8d184f7
> git fetch origin
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From
https://github.com/chalstrick/dondalfi
* [new branch] testFetch -> origin/testFetch
> git fetch origin a29d652966d835393dfc98e7d266d1e4c8d184f7:newBranch
From
https://github.com/chalstrick/dondalfi
* [new ref] a29d652966d835393dfc98e7d266d1e4c8d184f7 -> newBranch
I already asked this question on
StackOverflow, but I need to confirm if there's a way to do that. In Git, it's possible to fetch specific commit (along with its ancestors of course) using the commit's SHA, so calling git
fetch origin 57eab609d9efda3b8ee370582c3762c0e721033d:HEAD is perfectly normal. However, trying to do so with JGit fails, since FetchProcess tries to match
the source of the passed RefSpec with the advertisedRefs, which
are only the branches and tags.
Is there any way I can fetch a specific commit from a remote repository?