私はNGitを使用して次のことを実行しようとしていますが、ほぼ1日後に完全に失われます。
- 空のリポジトリを作成する
- URLとクレデンシャルを使用してリモートの「オリジン」を追加します
- Ls-Remoteを実行して、
master
ブランチの最新のハッシュを取得しますorigin
誰かが私にこれの実際の例を見せてくれるなら、私はそれを大いに感謝します
using System.Collections.Generic;
using System.Linq;
using NGit.Api;
using Sharpen;
// git init
string path = @"C:\git\repo1";
Git git = Git.Init().SetDirectory(new FilePath(path)).Call();
// after init, you can call the below line to open
// Git git = Git.Open(new FilePath(path));
// git remote origin
StoredConfig config = git.GetRepository().GetConfig();
config.SetString("remote", "origin", "url", @"http://user:password@github.com/user/repo1.git");
config.Save();
// git ls-remote
ICollection<Ref> refs = git.LsRemote().SetRemote("origin").Call();
Ref master = refs.FirstOrDefault(a => a.GetName() == "refs/heads/master");
if (master != null)
{
string hash = master.GetObjectId().Name;
}