2017-12-29 6 views
-1

JGitを使用してすべてのローカルコミットをリモート(裸のリポジトリ)にプッシュできます。JGitを使用して特定のコミットがリモートリポジトリに変更されるまで

RefSpec spec = new RefSpec("master:master"); 
Iterable<PushResult> resultIterable = git.push().setRemote("origin").setRefSpecs(spec).call(); 

ここでは、特定のコミットまで変更をプッシュしたいと思います。以下はgitシェルコマンドです。これと同等のJGit実装が必要です。

git push <remotename> <commit SHA>:<remotebranchname> 
+2

それは 'スペック=新RefSpec( " ")で動作します;'と '.setRemote(" ") '? – ElpieKay

+0

試行されましたが、以下のエラーが発生しました: org.eclipse.jgit.api.errors.TransportException:remote:エラー:無効なプロトコル: 'old new ref'がありました – prasadK

+0

上記の例外はgit浅いので、 $ git fetch --unshallow 致命的:完全なリポジトリで--unshallowが意味をなさない – prasadK

答えて

0

ここにサンプルがあります。私はgit-bashでいくつかの準備をしました。

#init foo as the local repository 
cd /e/ 
git init foo 
#init bar as the remote repository 
git init bar 
#create two commits in the local repository 
cd foo 
> a 
git add . 
git commit -m 'root' 
#the first sha1 is b8d35be23d9f4574c9da81cf2fddb4212daf92a1 
> b 
git add . 
git commit -m 'ab' 
#create a remote pointing to /e/bar 
git remote add bar /e/bar 

git push bar b8d35be23d9f4574c9da81cf2fddb4212daf92a1:refs/heads/newbranchをシミュレートし、コードを試してみてください。

try { 
     Git git = Git.open(new File("E:/foo/.git")); 
     RefSpec spec = new RefSpec("b8d35be23d9f4574c9da81cf2fddb4212daf92a1:refs/heads/newbranch"); 
     git.push().setRemote("bar").setRefSpecs(spec).call();    
} catch (Exception e) { 
     System.out.println(e); 
} 
関連する問題