【发布时间】:2018-03-15 06:04:32
【问题描述】:
我使用下面的代码来做推送。
public static void main(String[] args) throws IOException,GitAPIException
{
Repository localRepo = new
FileRepository("C:\\Users\\Joshi\\Desktop\\demo");
Git git = new Git(localRepo);
// add remote repo:
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
try {
remoteAddCommand.setUri(new
URIish("https://bitbucket.org/nidhi011/bxc"));
System.out.println("file Added");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// you can add more settings here if needed
remoteAddCommand.call();
git.commit().setMessage( "commited" ).call();
// push to remote:
PushCommand pushCommand = git.push();
pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider("username", "password"));
// you can add more settings here if needed
pushCommand.call();
}
而我的错误是
file Added
Exception in thread "main"
org.eclipse.jgit.api.errors.WrongRepositoryStateException: Cannot commit on
a repo with state: BARE
at org.eclipse.jgit.api.CommitCommand.call(CommitCommand.java:171)
at maven_git.push.main(push.java:38)
运行上面的代码后我得到这个异常错误请帮我解决jgit push命令。是的,当我执行此代码时,还有一件事会在我的本地目录“demo”文件夹中生成配置文件,我无法理解。
【问题讨论】:
-
原因:org.eclipse.jgit.errors.TransportException: 没什么可推送的。 也许你需要一个 git.add 和一个 git.commit 首先?
-
@jonhid 先生是的,我已经完成了提交,然后我还收到“线程“主”org.eclipse.jgit.api.errors.WrongRepositoryStateException 中的异常错误:无法提交状态为:BARE 的仓库在 org.eclipse.jgit.api.CommitCommand.call(CommitCommand.java:171) 在 maven_git.push.main(push.java:38)"
-
在启动 Java 程序之前,您的目录
demo是 Git 存储库吗? -
@MincongHuang 是的,有 .git 文件夹