我需要使用git plumbing命令(例如chapter 9 of the git book中使用的那些命令),如git hash-object
,git write-tree
,git commit-tree
和其他所有。有没有一个很好的API在JGit中做这些(我似乎无法找到一个),或者你将如何做一些基本的事情,比如从输出流或文件写入blob /你使用什么而不是git命令?是否有JGit管道API?
1
A
回答
1
如果有,应该在JGit。
例如,DirCache
对象(即,GIT中指数)具有WriteTree function:
/**
* Write all index trees to the object store, returning the root tree.
*
* @param ow
* the writer to use when serializing to the store. The caller is
* responsible for flushing the inserter before trying to use the
* returned tree identity.
* @return identity for the root tree.
* @throws UnmergedPathException
* one or more paths contain higher-order stages (stage > 0),
* which cannot be stored in a tree object.
* @throws IllegalStateException
* one or more paths contain an invalid mode which should never
* appear in a tree object.
* @throws IOException
* an unexpected error occurred writing to the object store.
*/
public ObjectId writeTree(final ObjectInserter ow)
2
欢迎JGit API。除了包装org.eclipse.jgit.api
中的高级瓷器API之外,低级别的API并不与本地git的管道命令密切相关。这是由于JGit是Java库而不是命令行界面。
如果您需要示例,请首先查看> 2000个JGit测试用例。接下来看看EGit如何使用JGit。如果这无助于回来并提出更具体的问题。
1
git的散列的对象<文件>
import java.io.*;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectInserter.Formatter;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
public class GitHashObject {
public static void main(String[] args) throws IOException {
File file = File.createTempFile("foobar", ".txt");
FileOutputStream out = new FileOutputStream(file);
out.write("foobar\n".getBytes());
out.close();
System.out.println(gitHashObject(file));
}
public static String gitHashObject(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
Formatter formatter = new ObjectInserter.Formatter();
ObjectId objectId = formatter.idFor(OBJ_BLOB, file.length(), in);
in.close();
return objectId.getName(); // or objectId.name()
}
}
预期输出:323fae03f4606ea9991df8befbb2fca795e648fa
如Assigning Git SHA1's without Git
相关问题
- 1. JGIT验证存储库是否有效
- 2. bash中是否有管道映射?
- 3. 管道是否有'liftIO`等价物?
- 4. Azcopy是否支持管道?
- 5. 是否有kernel32.searchpath的托管API?
- 6. 是否有AppHarbor管理域的API?
- 7. 是否有API API?
- 8. 是否有一个领域知道Youtube API是否验证了YouTube频道?
- 9. JGit是否支持Git凭证?
- 10. 是否有托管API来管理IIS 8?
- 11. 有没有人知道是否有Project Natal的.NET API?
- 12. 管道是否写入标准输入?
- 13. GStreamer的管道是否显示图片
- 14. “ret”是否会拖延管道?
- 15. 检查stdin管道是否为空C
- 16. PowerShell管道是否连续进料?
- 17. TransmitFile是否在管道上工作?
- 18. C++管道:是否等待写入
- 19. 是否有可能有一个GAE通道API到iphone?
- 20. HN是否有API?
- 21. LISTSERV是否有API?
- 22. ADrive.com是否有API?
- 23. 是否有OpenGrok API?
- 24. Hackage是否有API?
- 25. 是否有Aardvark API?
- 26. 是否有任何git管道比git diff-files更快?
- 27. 是否有绕过导轨资产管道的导轨选项?
- 28. 是否有可能降低管道的吞吐量?
- 29. 是否有一个管道命令来创建标签对象?
- 30. 是否有可能在Windows中发现命名管道?