[英]How to Properly Unstage File With libgit2sharp
我正在盡力弄清楚如何使用 libgit2sharp 取消暫存文件。
我目前的方法是從索引中刪除文件,但這似乎是刪除文件而不是取消暫存。
public bool Unstage(params string[] filePaths)
{
using (var repo = LocalRepo)
{
try
{
foreach (var filePath in filePaths)
{
repo.Index.Remove(filePath);
repo.Index.Write();
}
}
catch (Exception ex)
{
return false;
}
}
return true;
}
我也嘗試過軟重置,但我不知道如何在重置函數重載之一中傳遞文件名或使用 commitish 參數。
一直在嘗試關注這篇文章: 為什么有兩種方法可以在 Git 中取消暫存文件? ,但我似乎無法弄清楚如何在 libgit2sharp 中重新創建該方法。
經過一段時間的搜索,我終於發現 libgit2sharp 有一個 Commands 靜態類,其中包含幾乎所有您需要內置的命令,並最終這樣做:
public bool Unstage(params string[] filePaths)
{
using (var repo = LocalRepo)
{
try
{
foreach (var filePath in filePaths)
{
Commands.Unstage(repo, filePath);
}
}
catch (Exception ex)
{
return false;
}
}
return true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.