我需要使用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中發現命名管道?