19

JGit をいじってみました。あるリポジトリからリモートを正常に削除できました ( git remote rm origin) git remote add origin http://github.com/user/repo

削除するには、次のようにします。

StoredConfig config = git.getRepository().getConfig();
config.unsetSection("remote", "origin");
config.save();

しかし、のようなオプションはありません#setSection(String, String)

前もって感謝します。

4

3 に答える 3

34

そのように動作するように管理しました:

Git git = new Git(localRepository);
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", "http://github.com/user/repo");
config.save();

そしてどうやらそれは上司のように機能します。

于 2012-10-09T13:37:27.290 に答える
0

git24jでリモートオブジェクトを直接操作できます

Repository repo = Repository.open("your-repository");
Remote upstream = Remote.create(repo, "upstream", URI.create("http://github.com/user/repo"));

もちろん、git-config API を使用して同じことを行うこともできます。

Config cfg = Config.openOndisk("my-git.config");
cfg.setString("remote.url", "http://github.com/user/repo");
于 2020-09-15T05:21:02.013 に答える