问题
I was trying JGit, for project like
sample--
|-- src
|---sampletest
|------Test.txt
I make this git project by repo.create()
in JGit, and I can find .git inside sample. But whenever I modified the Test.txt. It was not displayed in git status from terminal.
I am unable to figure out the answer.
Also is there any other Java API that can be used?
EDIT
This project does not have .git intially. I did,
repository = new FileRepository(<somepath>/sample/+".git");
git = new Git(repository);
This creates a .git inside sample. Git status from terminal:
C:\Users\msrivastava\Documents\GitHub\sample> git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/
nothing added to commit but untracked files present (use "git add" to track)
So After repo.create(), it does not add or commit the sample/src/*
After all this I load the sample project git repo. And perform add with file pattern "src/*" and "src/sampletest/Test.txt"
repository = new FileRepository(<somepath>/sample/+".git");
git = new Git(repository);
git.add().addFilePattern("src/*").call();
Also
git.add().addFilePattern("src/sampletest/Text.txt").call();
Git status from terminal after this:
C:\Users\msrivastava\Documents\GitHub\sample [master +1 ~0 -0 !]> git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/
nothing added to commit but untracked files present (use "git add" to track)
回答1:
The counterpart of git status
in JGit is the StatusCommand
. It can be obtained from the Git command factory and called like so:
Repository repo = ...
Git git = Git.wrap( repo );
Status status = git.status().call();
The getters of Status
return the paths of the added, removed, modified, tracked, etc. files.
来源:https://stackoverflow.com/questions/23508315/git-status-does-not-show-changes-when-creating-repo-in-jgit