Provides examples and code snippets for the JGit Java Git implementation.
The JGit framework is rich and diverse, it has two layers, a low-level api and a higher-level set of porcelain commands.
This project tries to provide a collection of ready-to-run snippets which try to augment the existing JavaDoc and the User Guide
git clone git://github.com/centic9/jgit-cookbook
mvn dependency:sources eclipse:eclipse package
Import the project into an Eclipse workspace and execute the snippets there.
- Get the SHA-1 ref from a name, e.g. refs/heads/master
- Get the commit-object from a name or a SHA-1
- Get the tree-object from a commit-object, name or SHA-1
- Read the contents of a file/blob
- Get the tag-object from a name or a SHA-1
- Resolve complex references, e.g. HEAD^^ to a SHA-1
- Iterate over the commits on a branch
- Read contents of a specific file from a specific commit
- List remotes configured for the current repository
- Print out user information from Git
- Read file attributes, e.g. executeable state, file or directory, size, ...
- Iterate all commits of a repository - https://gerrit.googlesource.com/plugins/branch-network/+log/refs/heads/master/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/data/JGitFacade.java
- Take some of the unit tests as example: https://github.com/eclipse/jgit/tree/master/org.eclipse.jgit.test/tst/org/eclipse/jgit/api
The following sources were used to build the snippets
Please note that the list of snippets is not yet complete, probably never will. If you are missing things or have suggestions how to improve or add snippets, please either send pull requests or create issues.