如何在不更改工作目录的情况下获取JGit分支的所有提交?
不幸的是JGit文档不是很好......
用砂砾红宝石很容易:
repo = Grit::Repo.new(pathToRepo)
repo.commits(branchName, false).each do |commit|
    doSomethingWithTheCommit
end
再见,hurik
我一直在研究基于Java的产品,Git功能将被集成到该产品中.使用Git功能之一,我已经通过staging将10多个文件添加到Git存储库中,然后在单个提交中提交它们.
上述过程的反向可能吗?即找到作为提交的一部分提交的文件列表.
我在git.log()命令的帮助下得到了提交,但我不知道如何获取提交的文件列表.
示例代码:
Git git = (...);
Iterable<RevCommit> logs = git.log().call();
for(RevCommit commit : logs) {
    String commitID = commit.getName();
    if(commitID != null && !commitID.isEmpty()) {
    TableItem item = new TableItem(table, SWT.None);
    item.setText(commitID);
    // Here I want to get the file list for the commit object
}
}
最近将 Jgit 升级到 5.10.0.202012080955-r。之后,我们将IOException克隆一个裸 git 存储库。到目前为止,它似乎没有造成任何明显的功能影响,但它引起了人们的关注。此问题仅在 Kubernetes 部署中出现,在 Junit 测试中不会出现。这是一个已知问题吗?如果是,有什么解决方法或这里缺少什么吗?
谢谢。
[36morg.eclipse.jgit.util.FS                [0;39m [2m:[0;39m Cannot save config file 'FileBasedConfig[/.config/jgit/config]'
java.io.IOException: Creating directories for /.config/jgit failed
    at org.eclipse.jgit.util.FileUtils.mkdirs(FileUtils.java:411) ~[org.eclipse.jgit-5.10.0.202012080955-r.jar!/:5.10.0.202012080955-r]
    at org.eclipse.jgit.internal.storage.file.LockFile.lock(LockFile.java:130) ~[org.eclipse.jgit-5.10.0.202012080955-r.jar!/:5.10.0.202012080955-r]
    at org.eclipse.jgit.storage.file.FileBasedConfig.save(FileBasedConfig.java:219) ~[org.eclipse.jgit-5.10.0.202012080955-r.jar!/:5.10.0.202012080955-r]
    at org.eclipse.jgit.util.FS$FileStoreAttributes.saveToConfig(FS.java:735) ~[org.eclipse.jgit-5.10.0.202012080955-r.jar!/:5.10.0.202012080955-r]
    at org.eclipse.jgit.util.FS$FileStoreAttributes.lambda$4(FS.java:424) ~[org.eclipse.jgit-5.10.0.202012080955-r.jar!/:5.10.0.202012080955-r]
    at org.eclipse.jgit.util.FS$FileStoreAttributes$$Lambda$1660/0x00000000f4008230.run(Unknown Source) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:836) ~[na:na]
我找不到jgit的javadocs.我尝试使用maven构建jgit,但构建失败,所以我请求你的帮助.我在哪里可以找到jgit的javadocs.
想象一下Git背后的数据结构.它就像一个有条理的持久性数据结构,除了使用散列引用而不是传统的指针.
我需要Git的数据结构,除了没有任何工作树和索引的东西.并且将有数百万个分支机构,每个分支机构跟踪少数其他本地分支机构.提交和合并将在不同的线程上每分钟发生几千次.拉动会每秒发生一次.
在libgit2和jgit之间我可以使用Git的数据存储子系统.
但我使用合适的工具吗?是否有一个具有git功能的数据库,但更快/更多并发/可扩展/更少阻抗不匹配?内存缓存写入非常有用.
一个协作编辑的游戏.每个玩家都有自己的分支,他们对游戏世界所做的每一项改变都只适用于他们的版本.可信用户将更改合并回"主"分支.数据和源代码通常捆绑在一起,需要相同的分支和合并功能.
在JGit,我搜索推送分支并添加上游引用(跟踪)的方法.
它是期权-u或--set-upstream成推命令.
我没有在课堂上看到PushCommand允许这样做的方法.
拜托,你能告诉我怎么做吗?
PushCommand pushCommand = git.push()
                    .setRemote(remoteAlias)
                    .setRefSpecs(spec);
使用JGit,我希望尽可能获得提交文件中的更改列表git log --full-history -p -1 <hash-id>.
这可能吗?如果是这样,你怎么做?
我知道如何获取每个提交,并查看提交消息:
//Load repo
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(new File("/path/to/repo/.git")).setMustExist(true).build();
Git git = new Git(repo);
//get commits
Iterable<RevCommit> log = git.log().call();
for (RevCommit commit : log) {
    //Shows the hashid
    System.out.println("LogCommit: " + commit);
    //Shows only commit message
    String logMessage = commit.getFullMessage();
    System.out.println("LogMessage: " + logMessage);
}
git.close();
是什么让我得到文件的变化?
例如我写道:
git log --full-history -p -1 8309c1262e1b7ffce8fc86efc1ae5777a4a96777
回应是
commit 8309c1262e1b7ffce8fc86efc1ae5777a4a96777
Author: <redacted>
Date:   Thu Aug 4 12:15:23 2016 -0400 …我试图在文件的两次提交之间显示一个git diff.基本上,我这样做是为https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java
您可以在https://github.com/svenhornberg/JGitDiff下查看我的完整代码
public class RepoDiff {
    public void compare(byte[] fileContentOld, byte[] fileContentNew) {
        try {
            Repository repository = createNewRepository();
            Git git = new Git(repository);
            // create the file
            commitFileContent(fileContentOld, repository, git, true);
            commitFileContent(fileContentNew, repository, git, false);
            // The {tree} will return the underlying tree-id instead of the commit-id itself!
            ObjectId oldHead = repository.resolve("HEAD^^^^{tree}");   //here is my nullpointer
            ObjectId head = repository.resolve("HEAD^{tree}");
            System.out.println("Printing diff between tree: " + oldHead + " and " + head);
            // prepare …我想使用 JGit 在存储库中获取最后一个提交元数据(按日期计算的最年轻的元数据)。
我知道我可以使用
try (RevWalk walk = new RevWalk(repository)) {
    RevCommit commit = walk.parseCommit(repository.resolve(commitHash));
}
但是如何获得最新的提交哈希?
有没有其他方法可以RevCommit直接在存储库中获得最年轻的日期?