LibGit2Sharp Pull() 不拉取已删除的文件
LibGit2Sharp Pull() not pulling deleted files
我制作了一个程序来从我的 github.Cloning 上托管的 public 存储库中提取一个项目工作得很好(无论如何我都是这样做的),但我一直在努力得到它努力拉动一切,一旦你删除了一个文件,它就不再拉动那个文件了。在我的例子中,我从拉取的存储库(基本上是克隆的存储库)中删除了 .gitignore,现在 repo.Network.Pull()
不想从存储库中重新下载它。我删除的任何其他文件也是如此。
private void PullButton_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(BrowseText.Text))
if (Directory.Exists(BrowseText.Text))
{
AddToDebugBox("Starting Pull request to \"" + BrowseText.Text + "\"...");
if (!Repository.IsValid(BrowseText.Text))
{
AddToDebugBox("No Git init found at: \"" + BrowseText.Text + "\"...");
Repository.Clone("https://github.com/sxbrentxs/FPS-GLU.git", BrowseText.Text);
AddToDebugBox("Created new git init at: \"" + BrowseText.Text + "\".");
}
else
{
AddToDebugBox("Found git init at: \"" + BrowseText.Text + "\".");
using (Repository repo = new Repository(BrowseText.Text))
{
AddToDebugBox("Starting pull request...");
PullOptions options = new PullOptions();
options.FetchOptions = new FetchOptions();
repo.Network.Pull(new Signature("Updater", "Updater@RoZoShoGitUpdater.nl", new DateTimeOffset(DateTime.Now)), options);
AddToDebugBox("Completed pull request.");
AddToDebugBox("Calculating differences...");
TreeChanges changes = repo.Diff.Compare<TreeChanges>();
AddToDebugBox(string.Format("{0} files changed.", changes.Count()));
foreach (TreeEntryChanges c in changes)
AddToDebugBox(string.Format("Path: {0} | Change made: {1}", c.Path, c.Status));
}
AddToDebugBox("Operations completed.");
cleanready = !cleanready;
}
}
else
AddToDebugBox("Cannot pull to non-existing path: \"" + BrowseText.Text + "\"...");
else
AddToDebugBox("Cannot pull to nothing: \"" + BrowseText.Text + "\"...");
}
这是我按下下拉按钮后的日志:
23:41:55 > Folder: "E:\Projects\Test" selected.
23:41:58 > Starting Pull request to "E:\Projects\Test"...
23:41:58 > Found git init at: "E:\Projects\Test".
23:41:58 > Starting pull request...
23:41:59 > Completed pull request.
23:41:59 > Calculating differences...
23:41:59 > 1 files changed.
23:41:59 > Path: .gitignore | Change made: Deleted
23:41:59 > Operations completed.
我忘记了什么或做错了什么?
您只需要像使用 git
:
强制检出到 "master" 分支头部的示例:
head = repo.Branches.Single (branch => branch.FriendlyName == "master");
var checkoutOptions = new CheckoutOptions ();
checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force;
repo.Checkout (head, checkoutOptions);