我正在尝试git log filename使用pygit2在git裸存储库中进行相当的操作.该文档仅解释了如何执行git log此操作:
from pygit2 import GIT_SORT_TIME
for commit in repo.walk(oid, GIT_SORT_TIME):
print(commit.hex)
Run Code Online (Sandbox Code Playgroud)
你有什么主意吗?
谢谢
编辑:
我现在有类似的东西,或多或少精确:
from pygit2 import GIT_SORT_TIME, Repository
repo = Repository('/path/to/repo')
def iter_commits(name):
last_commit = None
last_oid = None
# loops through all the commits
for commit in repo.walk(repo.head.oid, GIT_SORT_TIME):
# checks if the file exists
if name in commit.tree:
# has it changed since last commit?
# let's compare it's sha with the previous found sha
oid = commit.tree[name].oid
has_changed …Run Code Online (Sandbox Code Playgroud) 我有一个相对较短的Gist,它应该libgit2用来模拟git pull命令的功能.不幸的是,它并没有完全奏效.
总之,代码片段:
git_repository_open()打开磁盘上的存储库git_remote_load()以获取git_remote *名为"origin"的远程控件git_remote_connect()用GIT_DIRECTION_FETCH旗帜打电话git_remote_download()从远程获取对象根据git_remote_stats(),物体确实被取出.但工作目录不会更改以反映最新提交.我尝试添加:
git_checkout_head(repo, NULL);
Run Code Online (Sandbox Code Playgroud)
......但这没有任何区别.
输入:
git checkout master
...在终端中产生以下输出:
Already on 'master' Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
我如何快进?
有时我会尝试同时读取和写入Git存储库.但后来当我尝试提交文件时,我收到以下错误消息:
libgit2引发了一个错误.Category = Index(LockedFile).索引已锁定.这可能是由于同意或崩溃的过程.
提交按预期完成,为什么我收到此错误消息?我怎么摆脱它?
(如果LibGit2Sharp开发人员看到这一点:错误消息中存在拼写错误:concuRRRent.):D
git2go在将1.4.2升级到1.5之后,我在将OS X上的库编译为linux amd64时遇到了问题.
我认为这是关于交叉编译任何使用C代码和go 1.5的应用程序.
使用CGO_ENABLED=1,我得到:
$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 ./script/with-static.sh go install ./...
# runtime/cgo
ld: unknown option: --build-id=none
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
使用-compiler=gccgo,我得到:
$ GOOS=linux GOARCH=amd64 ./script/with-static.sh go install -compiler gccgo ./...
go build github.com/libgit2/git2go: : fork/exec : no such file or directory
Run Code Online (Sandbox Code Playgroud)
如果没有提供任何这些,我得到:
$ GOOS=linux GOARCH=amd64 ./script/with-static.sh go install ./...
can't load package: package github.com/libgit2/git2go: C source files not allowed when not …Run Code Online (Sandbox Code Playgroud) 我需要以编程方式使用C#获取Git历史记录中特定行的最后一位作者.我尝试使用libgit2sharp:
var repo = new LibGit2Sharp.Repository(gitRepositoryPath);
string relativePath = MakeRelativeSimple(filename);
var blameHunks = repo.Blame(relativePath);
// next : find the hunk which overlap the desired line number
Run Code Online (Sandbox Code Playgroud)
但这相当于命令
git blame <file>
事实上我需要
git blame -w <file> (比较时忽略空格)
Libgit2sharp不设置-w开关,也不提供任何参数/选项来设置它.我有什么选择?你知道其他任何与命令-w切换兼容的库blame吗?
在使用libgit2的C++中,我想创建一个新的本地存储库,其master分支基于specific-branch另一个本地存储库,保持其历史记录,以便稍后我可以在两者之间同步.
基本上,我尝试以下,除了使用libgit2:
所以,如果我的文件安排如下:
./old.git [branches:master,specific-branch]
./old/*[特定分支的./old.git文件和克隆]
命令的位置如下:
git init --bare ./new.git
cd ./old
git push ./new.git +specific-branch:master
Run Code Online (Sandbox Code Playgroud)
并想出类似的东西(删除错误检查以减少代码):
git_libgit2_init();
git_repository* repo = nullptr;
git_repository_init(&repo, "./new.git", true);
git_remote_create(&remote, repo, "origin", "./new.git");
git_remote_add_push(repo, "origin", "+specific-branch:master");
git_push_options optionsPush = GIT_PUSH_OPTIONS_INIT;
git_remote_push(remote, nullptr, &optionsPush);
Run Code Online (Sandbox Code Playgroud)
我不确定的是从这里开始的地方以及如何git_remote_push()正确地调用实际执行某些操作的地方.目前没有副作用,因为./old.git没有参考.也就是说,./new.git是正确创建的,但它不包含./old.git/的内容./old/*.
非常感谢.
基于建议采用"获取"方法的答案,我还尝试了以下方法:
git_repository* repo = nullptr;
if (git_repository_init(&repo, "./new.git", true)) {
FATAL();
}
git_remote* remote;
git_remote_create_anonymous(&remote, repo, "./old");
char* specs[] = { _strdup("specific-branch:master"), nullptr …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pygit2库.
好像我第一步陷入了困境.它的文档没有解释如何创建blob并将其添加到树中.它主要围绕如何使用现有的git存储库,但我想创建一个并添加blob,commit,...到我的repo.是否可以直接从文件创建blob,还是应该读取文件内容并设置blob.data?
from pygit2 import Repository
from pygit2 import init_repository
bare = False
repo = init_repository('test', bare)
Run Code Online (Sandbox Code Playgroud)
如何创建blob或树并将其添加到存储库?
我正在尝试使用库 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)
你有什么提示可能是错误的或一般如何做吗?
git2 箱没有直接的方法来执行“git pull”操作。
use std::fs;
use std::fs::File;
use std::io::{stderr, stdout, Write};
use std::path::Path;
use git2::{Commit, Error, Index, MergeOptions, ObjectType, Repository, ResetType};
struct Repo {
url: &'static str,
path: &'static str,
branch: &'static str,
}
impl Repo {
fn reset(&self, path: &Path) {
let repo = match Repository::open(path) {
Ok(repo) => repo,
Err(e) => panic!("Failed to open: {}", e),
};
repo.reset(
&repo.revparse_single("HEAD").unwrap(),
ResetType::Hard,
None,
)
.unwrap();
}
fn clone(&self) {
let repo = match Repository::clone(self.url, self.path) …Run Code Online (Sandbox Code Playgroud) 我尝试了解如何在libgit2 中实现自定义对象数据库。作为主要的切入点,我已经签出所谓的例子库libgit2,后端为它实现的例子memcached,mysql,redis和sqlite3。
但我还是不明白如何将这些插入到 libgit2 中?我是否插入了 libgit2 可以加载的共享库?或者我是否使用相应的后端源从头开始编译 libgit2?这种后端的范围是什么?任何见解都非常感谢!
动机:默认情况下 git 和 libgit打包/压缩对象。就我而言,我想实现一个不这样做的后端。(是的,有 LFS,但我试图找到一个 libgit2-only 解决方案)