### Get Help for JGit Version Command Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide View the help message for a specific JGit command, such as 'version', to understand its available flags and usage. ```bash prompt$ ./jgit version -h jgit version [--help (-h)]  --help (-h) : display this help text ``` -------------------------------- ### Registering BouncyCastleProvider in EGit Source: https://github.com/eclipse-jgit/jgit/wiki/New-and-Noteworthy-7.0 Example of how to manually register the BouncyCastleProvider security provider, as required by JGit 7.0.0 for certain GPG key types. ```java import java.security.Security; import org.bouncycastle.jce.provider.BouncyCastleProvider; // ... // Register BouncyCastleProvider if needed for AES/OCB support if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { Security.addProvider(new BouncyCastleProvider()); } ``` -------------------------------- ### Get Commit Log using Porcelain API Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Use the LogCommand to iterate over the commit history. Ensure a Git instance is initialized with a Repository. ```java Git git = new Git(db); Iterable log = git.log().call(); ``` -------------------------------- ### Get a Git Reference Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Query for a reference to HEAD, such as the master branch reference. ```java Ref HEAD = repository.getRef("refs/heads/master"); ``` -------------------------------- ### View JGit Branch Summary Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Get a summary of repository branches, their revisions, and commit message first lines using the 'branch -v' command. ```bash prompt$ ./jgit branch -v   master       4d4adfb Git Project import: don't hide but gray out existing projects * traceHistory 6b9fe04 [historyView] Add trace instrumentation ``` -------------------------------- ### Prepare Virtual Environment Source: https://github.com/eclipse-jgit/jgit/blob/master/tools/maven-central/README.md Sets up a virtual environment using pipenv for the download_release.py script. Ensure Python 3.14 is available. ```bash cd tools/maven-central pipenv --python 3.14 pipenv sync ``` -------------------------------- ### Initialize Git Repository Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Initializes a new Git repository. The 'dest' attribute specifies the path, and 'bare' determines if it's a bare repository. ```xml ``` -------------------------------- ### Build JGit CLI Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Build the jgit binary using Maven. Ensure you have the EGit git repository cloned and ready. ```bash ~/src/jgit$ mvn clean install ``` -------------------------------- ### List Common JGit Commands Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Run JGit with no arguments to display a list of the most commonly used commands and their brief descriptions. ```bash prompt$ ./jgit jgit --git-dir GIT_DIR --help (-h) --show-stack-trace command [ARG ...] The most commonly used commands are:  branch   List, create, or delete branches  clone    Clone a repository into a new directory  commit   Record changes to the repository  daemon   Export repositories over git://  diff     Show diffs  fetch    Update remote refs from another repository  init     Create an empty git repository  log      View commit history  push     Update remote repository from local refs  rm       Stop tracking a file  tag      Create a tag  version  Display the version of jgit ``` -------------------------------- ### Dummy Files for Backward Compatibility Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md To ensure backward compatibility with older clients, reftable-enabled repositories must contain specific dummy files and directories. ```text .git/HEAD, a regular file containing ref: refs/heads/.invalid .git/refs/, a directory .git/refs/heads, a regular file ``` -------------------------------- ### Find Children of a Commit Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide This Java snippet uses PlotWalk to find and process commits starting from a root commit. It's useful for visualizing commit history. ```java PlotWalk revWalk = new PlotWalk(repo()); ObjectId rootId = (branch==null)?repo().resolve(HEAD):branch.getObjectId(); RevCommit root = revWalk.parseCommit(rootId); revWalk.markStart(root); PlotCommitList plotCommitList = new PlotCommitList(); plotCommitList.source(revWalk); plotCommitList.fillTo(Integer.MAX_VALUE); return revWalk; ``` -------------------------------- ### Restrict RevWalk Graph Traversal Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Reduces memory usage by limiting the RevWalk traversal to only necessary commits. Mark the start commit and uninteresting commits to optimize the walk. ```java RevWalk walk = new RevWalk(repository); ObjectId from = repository.resolve("refs/heads/master"); ObjectId to = repository.resolve("refs/remotes/origin/master"); walk.markStart(walk.parseCommit(from)); walk.markUninteresting(walk.parseCommit(to)); // ... ``` -------------------------------- ### Launch Graphical Log Viewer Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Open the graphical log tool to visualize the revision graph and commit details. This command launches a GUI window. ```bash prompt$ ./jgit glog ``` -------------------------------- ### Index Block Format Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md Defines the structure of an index block, starting with a block type 'i', followed by block length, index records, restart offsets, and restart count. This block is part of the ref index. ```plaintext 'i' uint24( block_len ) index_record+ uint24( restart_offset )+ uint16( restart_count ) padding? ``` -------------------------------- ### Add Files to Index using Porcelain API Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Use the AddCommand to add files or patterns to the Git index. Ensure a Git instance is initialized with a Repository. ```java Git git = new Git(db); AddCommand add = git.add(); add.addFilepattern("someDirectory").call(); ``` -------------------------------- ### Log Record Key Format Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md Illustrates the structured key format for log records, combining the reference name with a reversed 64-bit update index for sorting purposes. ```text ref_name '\0' reverse_int64( update_index ) ``` -------------------------------- ### Create and Tag a JGit Release Source: https://github.com/eclipse-jgit/jgit/blob/master/tools/maven-central/README.md Use the `tools/release.sh` script to create a new release version, update version identifiers in pom.xml and OSGi manifests, and create a signed, annotated tag. ```bash ./tools/release.sh v6.1.0.202203080745-r ``` -------------------------------- ### Verify JGit Build Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Check your JGit build by running the 'version' command. This confirms the CLI is built and executable. ```bash prompt$ ./jgit version jgit version 0.10.0-SNAPSHOT ``` -------------------------------- ### Test Staged Release with Maven Source: https://github.com/eclipse-jgit/jgit/blob/master/tools/maven-central/README.md Builds the jgit-build-test project using a Maven profile (-Pcentral.manual.testing) to verify that artifacts of the new JGit release can be downloaded and used. ```bash mvn clean install -Pcentral.manual.testing ``` -------------------------------- ### Configure Reftable Storage Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md To enable reftable storage, the repository's configuration file must be updated to specify the repository format version and the refStorage extension. ```ini [core] repositoryformatversion = 1 [extensions] refStorage = reftable ``` -------------------------------- ### Create Symbolic Link for JGit Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Ease frequent JGit usage by creating a symbolic link to the binary, typically in a directory like /usr/local/bin. ```bash sudo ln -s /path/to/jgit /usr/local/bin/jgit ``` -------------------------------- ### List All JGit Debug Commands Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Display all available debug and test commands for JGit by running the 'debug-show-commands' command. ```bash prompt$ ./jgit debug-show-commands ``` -------------------------------- ### Build a JGit Repository Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Use FileRepositoryBuilder to construct a Repository object. It can scan the environment and file system for the Git directory. ```java FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File("/my/git/directory")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); ``` -------------------------------- ### Initialize SoftHSM Token Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/manual_tests.txt Initializes a new SoftHSM token with a specified slot, label, PIN, and SO-PIN. This is a prerequisite for importing keys and certificates. ```bash $ softhsm2-util --init-token --slot 0 --label "TestToken" --pin 1234 --so-pin 4567 ``` -------------------------------- ### Commit Changes using Porcelain API Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Use the CommitCommand to perform a commit. You can set the commit message and other options. Ensure a Git instance is initialized with a Repository. ```java Git git = new Git(db); CommitCommand commit = git.commit(); commit.setMessage("initial commit").call(); ``` -------------------------------- ### Configure PKCS#11 SSH Provider Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/README.md Specify the path to the PKCS#11 shared library in `~/.ssh/config` to enable SSH authentication using a hardware security module. ```properties PCKS11Provider /absolute/path/to/vendor/library.so ``` -------------------------------- ### Download JGit Release and Create Signatures Source: https://github.com/eclipse-jgit/jgit/blob/master/tools/maven-central/README.md Downloads a specified JGit release from repo.eclipse.org and generates artifact signature files (.asc) using your GPG signing key. ```bash pipenv run ./download_release.py 6.1.0.202203080745-r ``` -------------------------------- ### Create RSA Key and Certificate Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/manual_tests.txt Generates a new RSA 4096-bit key pair and a self-signed certificate using OpenSSL. The key is output to key.pem and the certificate to cert.pem. ```bash $ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -subj "/CN=MyCertTEST" -nodes ``` -------------------------------- ### Restrict Permissions for Configuration Files Source: https://github.com/eclipse-jgit/jgit/blob/master/tools/maven-central/README.md Secure your JReleaser configuration and GPG passphrase files by restricting read access to yourself. This is crucial for protecting sensitive credentials. ```bash chmod 600 ~/.jreleaser/config.toml chmod 600 ~/.gnupg/passphrase ``` -------------------------------- ### Import RSA Key Pair into SoftHSM Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/manual_tests.txt Imports the generated RSA private key (key.pem) into the SoftHSM token. Requires the slot ID, a label for the key, an ID, and the token PIN. ```bash $ softhsm2-util --import key.pem --slot 2006661923 --label "testkey" --id 1212 --pin 1234 ``` -------------------------------- ### Configure PKCS#11 Slot Index Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/README.md Set the `PKCS11SlotListIndex` in `~/.ssh/config` to select a specific PKCS#11 token if multiple are available. It is recommended to also include `IgnoreUnknown PKCS11SlotListIndex` to prevent OpenSSH errors. ```properties IgnoreUnknown PKCS11SlotListIndex ``` -------------------------------- ### Initialize RevWalk Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Initialize a RevWalk instance to walk a commit graph. This is used for parsing commits, tags, and trees. ```java RevWalk walk = new RevWalk(repository); ``` -------------------------------- ### Enable JGit Performance Tracing Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/config-options.md Set the GIT_TRACE_PERFORMANCE system property to true to trace timings from the progress monitor. This can be done via environment variable or programmatically. ```bash $ GIT_TRACE_PERFORMANCE=true jgit clone https://foo.bar/foobar Cloning into 'foobar'... remote: Counting objects: 1 [0.002s] remote: Finding sources: 100% (15531/15531) [0.006s] Receiving objects: 100% (169737/169737) [13.045s] Resolving deltas: 100% (67579/67579) [1.842s] ``` -------------------------------- ### Configure JReleaser Credentials for Maven Central Source: https://github.com/eclipse-jgit/jgit/blob/master/tools/maven-central/README.md Add your Maven Central username and token to the JReleaser configuration file. Ensure these files have restricted read access. ```toml JRELEASER_GITHUB_TOKEN="EMPTY" JRELEASER_MAVENCENTRAL_TOKEN="maven central token" JRELEASER_MAVENCENTRAL_USERNAME="maven central username" ``` -------------------------------- ### Reverse 64-bit Integer Function Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md Provides the implementation for the reverse_int64 function, used to invert a 64-bit integer value for lexicographical sorting of log records. ```text reverse_int64(int64 t) { return 0xffffffffffffffff - t; } ``` -------------------------------- ### Import Certificate into SoftHSM Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/manual_tests.txt Converts an X.509 certificate from PEM to DER format and then imports it into the SoftHSM token using pkcs11-tool. Requires the PKCS11 module path, object ID, label, and PIN. ```bash $ openssl x509 -in cert.pem -out cert.der -outform DER $ pkcs11-tool --module /opt/local/lib/softhsm/libsofthsm2.so -l --id 1212 --label "testcert" -y cert -w cert.der --pin 1234 ``` -------------------------------- ### Pushing Changes for Review Source: https://github.com/eclipse-jgit/jgit/blob/master/CONTRIBUTING.md Use this command to push your local commit to GerritHub for review. Ensure 'username' is replaced with your GitHub username. ```bash git push ssh://username@eclipse.gerrithub.io:29418/eclipse-jgit/jgit HEAD:refs/for/master ``` -------------------------------- ### Inspect Git Index with JGit CLI Tool Source: https://github.com/eclipse-jgit/jgit/wiki/FAQ Utilize the `jgit-cli.jar`'s `debug-show-dircache` command for a more detailed view of the Git index. This output includes mode, length, timestamp, object hash, and filename. ```bash $ java -jar jgit-cli.jar --git-dir /c/git/jgit/.git debug-show-dircache 100644 871 20100706,131532.000 dc701694e405702940dc97caada20a3e5d64bbba .eclipse_iplog 100644 17 20100219,165448.000 f57840b7eec86b91b135afc40f20d950c5d86988 .gitattributes 100644 1716 20100706,131532.000 1b85c64665f461a1ac948345c5f8034b751eda93 LICENSE ``` -------------------------------- ### Varint Decoding Logic Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md Illustrates the logic for decoding varint encoded values from a buffer, commonly used in pack files and reftables. ```java val = buf[ptr] & 0x7f while (buf[ptr] & 0x80) { ptr++ val = ((val + 1) << 7) | (buf[ptr] & 0x7f) } ``` -------------------------------- ### Log Record Types Source: https://github.com/eclipse-jgit/jgit/blob/master/Documentation/technical/reftable.md Enumerates the different types of log records, specifically '0x0' for deletions and '0x1' for standard git reflog data. ```text 0x0: deletion; no log data. 0x1: standard git reflog data using `log_data` above. ``` -------------------------------- ### Tag a Commit using Porcelain API Source: https://github.com/eclipse-jgit/jgit/wiki/User-Guide Use the TagCommand to create a tag for a specific commit. You can set the tag name, message, and other properties. Ensure a Git instance is initialized with a Repository. ```java Git git = new Git(db); RevCommit commit = git.commit().setMessage("initial commit").call(); RevTag tag = git.tag().setName("tag").call(); ``` -------------------------------- ### Inspect Git Index with Git CLI Source: https://github.com/eclipse-jgit/jgit/wiki/FAQ Use the `git ls-files -v -s` command to view the contents of the Git index. This shows file type, mode, object hash, stage, and filename. ```bash $ git ls-files -v -s] ) H 100644 dc701694e405702940dc97caada20a3e5d64bbba 0 .eclipse_iplog H 100644 f57840b7eec86b91b135afc40f20d950c5d86988 0 .gitattributes H 100644 1b85c64665f461a1ac948345c5f8034b751eda93 0 LICENSE ``` -------------------------------- ### Configure SSH for PKCS11 Provider Source: https://github.com/eclipse-jgit/jgit/blob/master/org.eclipse.jgit.ssh.apache/manual_tests.txt Configures the ~/.ssh/config file to use a SoftHSM library as a PKCS11 provider for a specific host. This enables SSH connections to use keys managed by the PKCS11 token. ```bash Host gitserver Hostname git.eclipse.org Port 29418 User ... PKCS11Provider /opt/local/lib/softhsm/libsofthsm2.so ```