Git status does not show changes when creating repo in JGit

爱⌒轻易说出口 提交于 2019-12-11 14:49:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!