我需要使用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. bash中是否有管道映射?
- 2. 管道是否有'liftIO`等價物?
- 3. Azcopy是否支持管道?
- 4. 是否有kernel32.searchpath的託管API?
- 5. 是否有API API?
- 6. 有沒有人知道是否有Project Natal的.NET API?
- 7. 「ret」是否會拖延管道?
- 8. 是否有可能有一個GAE通道API到iphone?
- 9. LISTSERV是否有API?
- 10. Hackage是否有API?
- 11. 是否有Aardvark API?
- 12. 是否有可能降低管道的吞吐量?
- 13. 命名管道名稱是否有反斜槓?
- 14. socketpair和一對未命名的管道是否有區別?
- 15. 是否有可能在Windows中發現命名管道?
- 16. 是否有可能不使用資產管道
- 17. 是否有一個管道命令來創建標籤對象?
- 18. 雅虎管道是否有一個不錯的選擇?
- 19. 如何知道我是否具有管理權限在Windows中?
- 20. 如何判斷管道上是否有新數據?
- 21. 是否有一種清理管道的簡單方法C
- 22. 是否有管理CoreOS
- 23. 是否有可能確定託管管道IIS7在ASP.NET中運行?
- 24. Bing API Azure Marketplace:如何知道是否有更多結果?
- 25. 是否有任何映射API提供道路詳細信息?
- 26. 是否有人知道基於黑莓Java開發的LinkedIn API?
- 27. 從安全的角度來看,管道是否認爲管道使用危險?
- 28. 是否可以創建管道模板,以便Jenkins自動生成管道?
- 29. 如何檢查每個管道元素的PowerShell管道是否返回true?
- 30. Azure虛擬機位置是否有任何管理API?