我试图以编程方式使用Rugged(libgit2的Ruby绑定)创建对现有存储库的提交.我试图遵循Rugged README中提供的文档,但我认为它与代码库的当前状态不完全匹配.我尝试运行以下代码时不断收到错误:
require 'rugged'
# Create an instance of the existing repository
repo = Rugged::Repository.new('/full/path/to/repo')
# grab the current Time object for now
curr_time = Time.now
# write a new blob to the repository, hang on to the object id
oid = repo.write("Some content for the this blob - #{curr_time}.", 'blob')
# get the index for this repository
index = repo.index
# add the blob to the index
index.add(:path => 'newfile.txt', :oid => oid, :mode …Run Code Online (Sandbox Code Playgroud) 如何从当前头部获得最后一个提交?
我想我需要获取当前的Branch(repo.Head),然后是SHA1(如何?)然后使用SHA1查找提交(如何?).
使用libgit2sharp我想做以下事情:
foreach( Commit commit in repo.Commits )
{
// How to implement assignedTags?
foreach( Tag tag in commit.assignedTags ) {}
}
Run Code Online (Sandbox Code Playgroud)
我想将所有标签分配给当前提交.什么是最好的方法呢?迭代所有标签,看看是否tag.Target.Sha == commit.Sha?多数表现不太好.还有另外一种方法吗?
我刚刚下载了libgit2sharp的nugget包.我发现即使是基本的操作也很难.
我有一个现有的git仓库(远程和本地).我只需要在它发生时提交新的更改并将其推送到远程.
我有下面的代码来解释我做了什么.
string path = @"working direcory path(local)";
Repository repo = new Repository(path);
repo.Commit("commit done for ...");
Remote remote = repo.Network.Remotes["origin"];
var credentials = new UsernamePasswordCredentials {Username = "*******", Password = "******"};
var options = new PushOptions();
options.Credentials = credentials;
var pushRefSpec = @"refs/heads/master";
repo.Network.Push(remote, pushRefSpec, options, null, "push done...");
Run Code Online (Sandbox Code Playgroud)
我应该在哪里指定远程网址?这也是做这些操作(提交和推送)的正确方法吗?
谢谢
我正在尝试使用库 nodegit(0.2.4 版)和 ssh 从 node.js 中的 teamforge 服务器克隆 git 存储库。我们的服务器向用户请求身份验证,当我尝试仅使用克隆方法而不传递选项时,我收到错误消息:“回调无法初始化 SSH 凭据”。
我在文件 private.key 和 public.key 中有私钥和公钥。它们位于我在网络风暴中设置为工作目录的目录中,因此位置应该不是问题。
没有找到如何做的例子(也许我错过了),但下面的代码是我得到的最接近的:
'use strict';
var nodegit = require("nodegit"),
Clone = nodegit.Clone,
cred = nodegit.Cred;
var options = {
remoteCallbacks: {
credentials: function () {
return cred.sshKeyNew('user', 'public.key', 'private.key', '');
}
}
};
Clone.clone("ssh://user@teamforgeserver.net/reponame", "localTmp", options)
.then(function(repo) {
var r = repo;
},
function(err){
var e = err;
}
);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
TypeError: Object #<Object> has no method 'isFulfilled' at value
(c:\...\proj\node_modules\nodegit\node_modules\nodegit-promise\lib\core.js:36:15)
Run Code Online (Sandbox Code Playgroud)
你有什么提示可能是错误的或一般如何做吗?
如何使用libgit2进行推送?(就像git push origin master在控制台上)
我想使用C版本.克隆,打开,添加文件到索引和提交工作就像魅力(见代码).
test-bare-repository是本地的.
不幸的是,参考和文档对我没有帮助.例子非常罕见,而且大部分已经过时(像这样,git_push_new() 功能似乎已经消失).
我现在猜几个小时了,我想我尝试了参考和示例中所有有意义的代码片段组合.
编辑:我担心根本不可能用libgit2做到这一点.任何人都可以建议我参考,非常/伪造我的恐惧?
还有一些消息来源([1] ,[2] )在互联网/邮件列表是说,这是不可能的libgit2推现在,但将有可能soonish.然而,这些来源已经过时了.
引用包含一些与推送相关的函数(至少按名称).但似乎没有一个像我想要的那样工作:(
我试图找到只有源代码发生变化的C/C++源代码的重大差异.我知道你可以使用git diff -G<regex>它,但它似乎非常有限的可以运行的正则表达式.例如,它似乎没有提供忽略C/C++中多行注释的方法.
在运行差异之前,git或者libgit2中是否有任何方法可以忽略注释(包括多行),空格等?或者一种确定diff输出中的一条线是否是注释的方法?
我已经查看了这篇文章中的答案(libgit2 (fetch & merge & commit)),但我正在努力让 Git Pull 工作。我没有收到错误消息。Fetch 似乎可以工作,但没有发生 Merge。做一个 Git 状态显示我的分支落后于 1 个提交......
On branch Branch_1_1.
Your branch is behind 'origin/Branch_1_1' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
我的代码在下面...
static int fetchhead_ref_cb(const char *name, const char *url,
const git_oid *oid, unsigned int is_merge, void *payload)
{
if ( is_merge )
{
strcpy_s( branchToMerge, 100, name );
memcpy( &branchOidToMerge, oid, sizeof( git_oid ) …Run Code Online (Sandbox Code Playgroud) 使用git show,我可以从特定的提交中获取特定文件的内容,而无需更改本地克隆的状态:
$ git show <file>
$ git show <commit>:<file>
Run Code Online (Sandbox Code Playgroud)
如何使用libgit2sharp以编程方式实现此目的?
我尝试了解如何在libgit2 中实现自定义对象数据库。作为主要的切入点,我已经签出所谓的例子库libgit2,后端为它实现的例子memcached,mysql,redis和sqlite3。
但我还是不明白如何将这些插入到 libgit2 中?我是否插入了 libgit2 可以加载的共享库?或者我是否使用相应的后端源从头开始编译 libgit2?这种后端的范围是什么?任何见解都非常感谢!
动机:默认情况下 git 和 libgit打包/压缩对象。就我而言,我想实现一个不这样做的后端。(是的,有 LFS,但我试图找到一个 libgit2-only 解决方案)