我正在寻找一种方法,可以将文件的所有更改从特定提交提交到当前HEAD。使用git实用程序,我只需调用git diff <sha1 of commit> <filename>
。 libgit2sharp是否可能?到目前为止,我刚刚实现libgit2sharp返回了在commit和HEAD之间更改的所有文件的更改。
预先感谢
编辑: 到目前为止我尝试过的是: 在文件显示的给定日期获取提交:
var results = repo.Commits.QueryBy(playlistName + ".txt").ToList();
Commit result = null;
foreach (LogEntry log in results)
{
if (verbose) resultString.Add(log.Commit.Author.When.ToString("dd/MM/yy:hh:mm"));
if (log.Commit.Author.When.Date.ToString("dd/MM/yy: hh:mm") == time.ToString("dd/MM/yy: hh:mm") || log.Commit.Author.When.Date.ToString("d") == time.ToString("d")) //search only for queried day
{
result = log.Commit;
}
尝试获取单个文件的差异:
Patch diff = repo.Diff.Compare<Patch>(result.Tree, repo.Head.Tip.Tree);
if (diff.Count() == 0) resultString.Add("No differences found!");
string rawText = diff.Content;
resultString.Add(String.Format("Changes in playlist: 0}",playlistName));
foreach (string line in rawText.Split('\n')) resultString.Add(line);