我计划用我的插件(一个 Visual Studio 2012 扩展)替换git.exefrom windows 路径的用法,以在当前文件的边缘显示 Git Diff。- https://github.com/laurentkempe/GitDiffMarginlibgit2sharpGitDiffMargin
我想知道是否有等效的方法libgit2sharp可以使用 来启动外部 difftool git difftool -y filename?
我正在尝试使用libgit2sharp以获取文件的先前版本.我希望工作目录保持原样,至少恢复到以前的状态.
我最初的方法是尝试存储,检查我想要的文件的路径,将其保存到字符串变量,然后存储弹出窗口.有没有办法存放流行音乐?我很难找到它.这是我到目前为止的代码:
using (var repo = new Repository(DirectoryPath, null))
{
var currentCommit = repo.Head.Tip.Sha;
var commit = repo.Commits.Where(c => c.Sha == commitHash).FirstOrDefault();
if (commit == null)
return null;
var sn = "Stash Name";
var now = new DateTimeOffset(DateTime.Now);
var diffCount = repo.Diff.Compare().Count();
if(diffCount > 0)
repo.Stashes.Add(new Signature(sn, "x@y.com", now), options: StashModifiers.Default);
repo.CheckoutPaths(commit.Sha, new List<string>{ path }, CheckoutModifiers.None, null, null);
var fileText = File.ReadAllText(path);
repo.CheckoutPaths(currentCommit, new List<string>{path}, CheckoutModifiers.None, null, null);
if(diffCount > 0)
; // stash Pop?
}
Run Code Online (Sandbox Code Playgroud)
如果有一种比使用Stash更简单的方法,那也会很有效.
我尝试通过LibGitSharp结帐Remotecranch.在git中你使用这个命令:
git fetch origin
git checkout -b test origin/test
Run Code Online (Sandbox Code Playgroud)
在较新的版本中它只是:
git fetch
git checkout test
Run Code Online (Sandbox Code Playgroud)
所以我尝试了这个代码:
repo.Fetch("origin");
repo.Checkout("origin/" + Name);
Run Code Online (Sandbox Code Playgroud)
Fetch和Checkout运行没有任何问题,但没有Remotebranch的副本.
有没有人有想法用其他方法检查远程?
我的另一种方法是在Repository中创建Branch并将其推送到Remote:
Branch newBranch = repo.Branches.Add(Name, repo.Branches["master"].Commits.First());
repo.Network.Push(newBranch);
Run Code Online (Sandbox Code Playgroud)
但我得到这个例外:
您尝试推送的分支"Test1"("refs/heads/Test1")不会跟踪上游分支.
也许我可以将Branch设置为上游分支,但我不知道如何.
编辑:我没有正确解释,所以我试着更好地描述Fetch和Checkout在我的程序中的作用.Fetch命令正确执行.现在,如果我使用checkout命令,它应该创建Remotebranch的本地分支,但它不会.我也试过repo.Checkout(name),没有"origin /",但是它会抛出异常:No valid git object identified by '...' exists in the repository.
运行repo.Network.Pull()命令后,我希望能够看到哪些文件已添加到存储库中,在存储库中进行了更改以及已从存储库中删除。我需要的只是文件的文件路径,以及它是添加/更新还是删除。
是否有捷径可寻?我曾尝试调查过,Diff.Compare()但不确定这样做是否正确。
我正在尝试使用LibGit2Sharp来git push origin使用以下内容
using(var repo = new Repository("path\to\repo\.git"))
{
var commit = repo.Commit("Commit message", author, committer);
var options = new PushOptions{ CredentialsProvider = (u, s, t) => new UserNamePasswordCredentials { Username = "username", Password = "password" } };
repo.Network.Push(repo.Branches("master"), options);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个LibGit2SharpException说
附加信息:无法设置代理:参数不正确.
但是在git bash中我做的一切都很好git push origin.
我们有NTLM代理正在工作,我正在推动内部网https远程URI.我已http://username:password@proxy.fqdn:80按如下方式配置代理:
通读了这个SO并在那里链接,似乎libgit2sharp应该找到代理参数就好了.有没有人得到这个工作behing ntlm?
我正在使用:Windows 7,LibGit2Sharp.0.22.0,Git 2.10.1.windows.1,bash 4.3.46,.net4.5.2
关于实现推动替代方案的任何想法/技巧也非常受欢迎!
可以使用git rev-list命令获取后面/前面的提交数量。我正在尝试使用libgit2sharp库来实现同样的事情,但是该库没有完整记录,所以我找不到如何实现。
我正在寻找一个使用 获取后面/前面提交号的示例libgit2sharp。
使用libgit2sharp我想从一个特定的 git 远程分支拉(fetch + merge)最新到我当前签出的本地分支,而不必传递任何其他参数,比如用户凭据等。基本上我试图复制git pull origin my-remote-branch
我想从 C# 自动化某些 Git 操作。我可以通过调用git.exe(如果我知道路径)简单地做我想做的事,比如git.exe --git-dir=my-repo-directory pull origin my-remote-branch. 请注意,这里我必须提供的唯一外部参数是my-repo-directory和my-remote-branch。Git 让一切都正确,比如姓名、密码、电子邮件、当前工作分支(即使它没有远程连接),而 git pull 就可以正常工作。我不必手动传递任何这些参数。我假设 Git 从 repo 的当前 Git 设置中获取它们(来自 %HOME% 文件夹?)。
有没有办法在 LibGit2Sharp 中模拟它?
using (var repo = new Repository("my-repo-directory"))
{
PullOptions pullOptions = new PullOptions()
{
MergeOptions = new MergeOptions()
{
FastForwardStrategy = FastForwardStrategy.Default
}
};
MergeResult mergeResult = Commands.Pull(
repo,
new …Run Code Online (Sandbox Code Playgroud) 这是 Server 2016与net471它应该表现得像windows 10.
所以我通过nuget LibGit2Sharp prerelease我的下载paket.dependencies,解决了
LibGit2Sharp (0.26.0-preview-0027)
LibGit2Sharp.NativeBinaries (1.0.226) - restriction: >= netstandard2.0
Run Code Online (Sandbox Code Playgroud)
在一个新的fsi(使用ionide)我可以引用LibGit2Sharp.dll和打开LibGit2Sharp命名空间,但实例化一个存储库会引发以下错误:
Microsoft (R) F# Interactive version 10.1.0 for F# 4.1
> #r "../../packages/play/LibGit2Sharp/lib/netstandard2.0/LibGit2Sharp.dll";;
--> Referenced 'd:\scripts2dev\libwba\src\play\../../packages/play/LibGit2Sharp/lib/netstandard2.0/LibGit2Sharp.dll' (file may be locked by F# Interactive process)
> open LibGit2Sharp;;
> let repo = new Repository("path\to\repo.git");;
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-b0d9952': The …Run Code Online (Sandbox Code Playgroud) 我在一个存储库中有大量项目.我想确定所有这些项目的波动性,即最后一次提交是否会影响每个项目.我有一个所有项目路径的列表,我正在尝试为每个路径找到最后一次提交.我的代码看起来像这样:
public CommitInfo GetLastCommit(string path)
{
// resolve any \..\ and pathing weirdness
path = Path.GetDirectoryName(Path.GetFullPath(path));
var relativePath = path.Substring(BaseRepoPath.Length + 1).Replace("\\", "/");
if (!CommitCache.TryGetValue(relativePath, out CommitInfo result))
{
var options = new RepositoryOptions()
{
WorkingDirectoryPath = BaseRepoPath
};
using (var repo = new Repository(BaseRepoPath, options))
{
var filter = new CommitFilter()
{
IncludeReachableFrom = BranchName
};
var commit = repo.Commits.QueryBy(relativePath, filter).First().Commit;
result = new CommitInfo
{
When = commit.Author.When.DateTime,
Who = commit.Author.Name,
Message = commit.Message,
Files = commit.Tree.Select(x => …Run Code Online (Sandbox Code Playgroud) 希望有人打电话帮助。首先,我对 git 很陌生,所以如果我在解释我的问题时犯了一些错误,请原谅我。
我想使用 libgit2sharp 使用库将存在的源代码拉到特定的提交。所以如果有历史
我希望能够提取 5 或该列表中的任何其他数字的源代码。任何源都不会被标记,所以我必须使用提交来进行拉取。希望有人可以提供帮助。
我看过https://github.com/libgit2/libgit2sharp/wiki/git-pull但它似乎没有让我传入 sha 或提交 ID。
编辑我的问题以明确我正在使用图书馆。