@@ -8,7 +8,7 @@ JGit 项目由 Eclipse 维护,它的主页在 http://www.eclipse.org/jgit[]
8
8
==== 起步
9
9
10
10
有很多种方式可以让 JGit 连接你的项目,并依靠它去写代码。
11
- 最简单的方式也许就是使用 Maven 。你可以通过在你的 pom.xml 文件里的 `dependencies` 标签中增加像下面这样的片段来完成这个整合。
11
+ 最简单的方式也许就是使用 Maven 。你可以通过在你的 pom.xml 文件里的 ``< dependencies> ` 标签中增加像下面这样的片段来完成这个整合。
12
12
13
13
[source,xml]
14
14
----
@@ -25,7 +25,7 @@ JGit 项目由 Eclipse 维护,它的主页在 http://www.eclipse.org/jgit[]
25
25
如果你想自己管理二进制的依赖包,那么你可以从 http://www.eclipse.org/jgit/download[] 获得预构建的 JGit 二进制文件。
26
26
你可以像下面这样执行一个命令来将它们构建进你的项目。
27
27
28
- [source,shell ]
28
+ [source,console ]
29
29
----
30
30
javac -cp .:org.eclipse.jgit-3.5.0.201409260305-r.jar App.java
31
31
java -cp .:org.eclipse.jgit-3.5.0.201409260305-r.jar App
@@ -41,9 +41,10 @@ JGit 的 API 有两种基本的层次:底层命令和高层命令。
41
41
42
42
[source,java]
43
43
----
44
- // 创建一个新仓库,路径必须存在
44
+ // 创建一个新仓库
45
45
Repository newlyCreatedRepo = FileRepositoryBuilder.create(
46
46
new File("/tmp/new_repo/.git"));
47
+ newlyCreatedRepo.create();
47
48
48
49
// 打开一个存在的仓库
49
50
Repository existingRepo = new FileRepositoryBuilder()
@@ -69,21 +70,21 @@ ObjectId masterTip = master.getObjectId();
69
70
ObjectId obj = repo.resolve("HEAD^{tree}");
70
71
71
72
// 装载对象原始内容
72
- ObjectLoader loader = r .open(masterTip);
73
+ ObjectLoader loader = repo .open(masterTip);
73
74
loader.copyTo(System.out);
74
75
75
76
// 创建分支
76
- RefUpdate createBranch1 = r .updateRef("refs/heads/branch1");
77
+ RefUpdate createBranch1 = repo .updateRef("refs/heads/branch1");
77
78
createBranch1.setNewObjectId(masterTip);
78
79
createBranch1.update();
79
80
80
81
// 删除分支
81
- RefUpdate deleteBranch1 = r .updateRef("refs/heads/branch1");
82
+ RefUpdate deleteBranch1 = repo .updateRef("refs/heads/branch1");
82
83
deleteBranch1.setForceUpdate(true);
83
84
deleteBranch1.delete();
84
85
85
86
// 配置
86
- Config cfg = r .getConfig();
87
+ Config cfg = repo .getConfig();
87
88
String name = cfg.getString("user", null, "name");
88
89
----
89
90
0 commit comments