在JGit中创建回购时,Git状态不会显示更改 [英] Git status does not show changes when creating repo in JGit

查看:140
本文介绍了在JGit中创建回购时,Git状态不会显示更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JGit,例如:

  sample  -  
| - src
| --- sampletest
| ------ Test.txt

我使这个git项目由JGit中的 repo.create(),我可以在示例中找到.git。但是每当我修改Test.txt。它没有显示在终端的git状态。



我无法找出答案。

还有

是否还有其他Java API可以使用?

编辑



项目没有.git内在。
我做了,

  repository = new FileRepository(< somepath> / sample / +.git); 
git = new Git(repository);

这会在示例中创建一个.git。
终端的Git状态:

  C:\ Users \ \\\\\\\\\\\\\\\\\\\\\ ; git status 
#在分支主机

#初始提交

#未记录文件:
#(使用git add< file> ;. ..包含在将要提交的内容中)

#src /
没有添加提交但未跟踪的文件存在(使用git add来跟踪)

所以在repo.create()之后,它不会添加或提交sample / src / *



毕竟,我加载了示例项目git repo。并执行添加文件模式src / *和src / sampletest / Test.txt

  repository = new FileRepository < somepath> /样品/ +) GIT中。; 
git = new Git(repository);
git.add()。addFilePattern(src / *)。call();

同样

 <$ 。C $ C> git.add()addFilePattern( SRC / sampletest / TEXT.TXT)调用(); 

来自终端的Git状态:

  C:\Users\msrivastava\Documents\GitHub\sample [master +1〜0 -0!]> git status 
#在分支主机

#初始提交

#未记录文件:
#(使用git add< file> ;. ..包含在将要提交的内容中)

#src /
没有添加提交但未跟踪的文件存在(使用git add来跟踪)


解决方案

git status 在JGit中是 StatusCommand 。它可以从 Git命令工厂中获得并调用,如下所示:

  Repository repo = .. 。
Git git = Git.wrap(repo);
状态状态= git.status()。call();

Status 的获得者返回添加,删除,修改,跟踪等文件。


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)

解决方案

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.

这篇关于在JGit中创建回购时,Git状态不会显示更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆