In a certain environment, git
cannot be installed due to reasons such as" you do not have sudo privileges "or" moss with make
".
I was in trouble, I tried it as one of the countermeasures, and it worked, so I will introduce it
(I tried my best to cross-compile, but I hope it helps people even if it doesn't work.)
"If you use jgit
, which is a Java implementation of git
, it will work anywhere with a JVM **."
As a whole flow,
It's like fetching eclipse / jgit and building it. I think you can build it if you can use the mvn
command.
(I think it works better than make
git
)
#Get the repository
#(I did it in an environment with a suitable git)
git clone [email protected]:eclipse/jgit.git
# (Or wget https://github.com/eclipse/jgit/tree/stable-4.I think you can download the zip at 11)
#Move directory
cd jgit/
#Check out to the current latest stable version
git checkout stable-4.11
#Install
mvn clean install
#Try running the built jgit
./org.eclipse.jgit.pgm/target/jgit --version
./org.eclipse.jgit.pgm/target/
is portable, and you can set this target
directory in the environment where you want the git
command.
** I think it's okay to build jgit
and the environment where you want to install jgit
** (believe in the Java slogan ** Write once, run anywhere ** ...).
After that, create a symbolic link with the following command with the name " git "
toward ./org.eclipse.jgit.pgm/target/jgit
.
#Create a symbolic with the name git ($Created in PWD)
ln -s ./org.eclipse.jgit.pgm/target/jgit git
If you pass the path here, you can treat it like a git
command.
** JGit is an implementation of git
in Java. ** **
The official statement is as follows, so it's not like hitting git
behind the scenes.
An implementation of the Git version control system in pure Java.
I think that the main usage is to handle instructions such as commit
and checkout
of git
from Java (or JVM language) programmatically. The following is an example.
//git commit example
Git git = new Git(db);
CommitCommand commit = git.commit();
commit.setMessage("initial commit").call();
//git log example
Git git = new Git(db);
Iterable<RevCommit> log = git.log().call();
It's like system ()
, so I think the main purpose is to operate it without hitting the git
command.
There is an official document on how to use it as a CLI like this time, and there should be no way to use it.
Regarding reliability, It seems that Eclipse is developing it, so it will be used in Eclipse as well, It seems to be used in Gitbucket (like the open source version of GitHub) written in Scala, so I think it's quite reliable.
(Note: The git
below is a symbolic link to jgit
)
$ git --version
jgit version 5.0.0-SNAPSHOT
$ git
jgit --git-dir GIT_DIR --help (-h) --show-stack-trace --version command [ARG ...]
The most commonly used commands are:
add Add file contents to the index
archive Zip up files from the named tree
branch List, create, or delete branches
checkout Checkout a branch to the working tree
clean Remove untracked files from the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
config Get and set repository or global options
daemon Export repositories over git://
debug-lfs-store Run LFS Store in a given directory
describe Show the most recent tag that is reachable from a commit
diff Show diffs
fetch Update remote refs from another repository
gc Cleanup unnecessary files and optimize the local repository
init Create an empty git repository
log View commit history
ls-remote List references in a remote repository
ls-tree List the contents of a tree object
merge Merges two development histories
push Update remote repository from local refs
reflog Manage reflog information
repo Parse a repo manifest file and add submodules
reset Reset current HEAD to the specified state
rm Stop tracking a file
show Display one commit
status Show the working tree status
tag Create a tag
version Display the version of jgit