gpt4 book ai didi

c# - LibGit2Sharp Pull() 不 pull 已删除的文件

转载 作者:行者123 更新时间:2023-11-30 23:26:44 31 4
gpt4 key购买 nike

我制作了一个程序来从我的 github 上托管的公共(public)存储库中提取数据。克隆一个项目工作得很好(无论如何我都是这样做的),但我一直在努力让它工作以提取所有内容,一旦你删除一个文件,它不再提取该文件。在我的例子中,我从 pull 的存储库(基本上是克隆的存储库)中删除了 .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 + "\"...");
}

这是我按下下 pull 按钮后的日志:

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 的 cmd 行一样执行强制 check out :

强制 check out 到“master”分支头的示例:

head = repo.Branches.Single (branch => branch.FriendlyName == "master");
var checkoutOptions = new CheckoutOptions ();
checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force;
repo.Checkout (head, checkoutOptions);

关于c# - LibGit2Sharp Pull() 不 pull 已删除的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36803823/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com