0%

使用并修改三方Repository

在日常工作中时不时的会用到别人的东西,自己会进行一些修改,当想提交的时候并不方便。

普遍的做法

普遍的做法是GitHub上Fork后,得到自己的Repository,此处以hexo-theme-next为例。

如进入https://github.com/theme-next/hexo-theme-next

点击右上角Fork,得到一个自己的Repository

https://github.com/YaoHuanyu/hexo-theme-next.git

然后git clone 下来之后进行一些修改编辑,命令示例如下。

1
$ git clone https://github.com/YaoHuanyu/hexo-theme-next.git themes/next

然后进入themes/next目录进行一些修改、编辑。再进行普通的提交操作(命令示例如下)即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# themes/next目录下,完成编辑修改后
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: _config.yml

no changes added to commit (use "git add" and/or "git commit -a")

$ git add .

$ git commit -m "Had modified something."
[master a9a65d4] Had modified something.
1 file changed, 1 insertion(+), 1 deletion(-)

$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 306 bytes | 306.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/YaoHuanyu/hexo-theme-next.git
d24c48e..a9a65d4 master -> master

以上配置OVER。但是,涉及一些私有的配置内容提交起来十分不便。而且Fork得来的项目仅仅能够Public,无法作为Private Repository。

复制Repository

镜像一个Repository(Mirroring a repository)

不采用Fork的方法。通过运行一个特殊的clone命令,然后镜像推送到新的Repository。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 在GitHub上创建一个新的Repository。

# 创建存储库的bare clone。
$ git clone --bare https://github.com/theme-next/hexo-theme-next.git

# 将镜像push到新的repository
$ cd hexo-theme-next.git

$ git push --mirror https://github.com/YaoHuanyu/mirror-themes-next.git
Enumerating objects: 12578, done.
Counting objects: 100% (12578/12578), done.
Delta compression using up to 12 threads
Compressing objects: 100% (4281/4281), done.
Writing objects: 100% (12578/12578), 8.02 MiB | 11.27 MiB/s, done.
Total 12578 (delta 7995), reused 12578 (delta 7995), pack-reused 0
remote: Resolving deltas: 100% (7995/7995), done.
To https://github.com/YaoHuanyu/mirror-themes-next.git
* [new branch] cdn -> cdn
* [new branch] funding -> funding
* [new branch] i18n -> i18n
* [new branch] imgbot -> imgbot
* [new branch] logo -> logo
* [new branch] master -> master
* [new tag] v6.0.0 -> v6.0.0
* [new tag] v6.0.1 -> v6.0.1
* [new tag] v6.0.2 -> v6.0.2
* [new tag] v6.0.3 -> v6.0.3
* [new tag] v6.0.4 -> v6.0.4
* [new tag] v6.0.5 -> v6.0.5
* [new tag] v6.0.6 -> v6.0.6
* [new tag] v6.1.0 -> v6.1.0
* [new tag] v6.2.0 -> v6.2.0
* [new tag] v6.3.0 -> v6.3.0
* [new tag] v6.4.0 -> v6.4.0
* [new tag] v6.4.1 -> v6.4.1
* [new tag] v6.4.2 -> v6.4.2
* [new tag] v6.5.0 -> v6.5.0
* [new tag] v6.6.0 -> v6.6.0
* [new tag] v6.7.0 -> v6.7.0
* [new tag] v7.0.0 -> v7.0.0
* [new tag] v7.0.1 -> v7.0.1
* [new tag] v7.1.0 -> v7.1.0
* [new tag] v7.1.1 -> v7.1.1
* [new tag] v7.1.2 -> v7.1.2
* [new tag] v7.2.0 -> v7.2.0
* [new tag] v7.3.0 -> v7.3.0
* [new tag] v7.4.0 -> v7.4.0
* [new tag] v7.4.1 -> v7.4.1
* [new tag] v7.4.2 -> v7.4.2
* [new tag] v7.5.0 -> v7.5.0
* [new tag] v7.6.0 -> v7.6.0
* [new tag] v7.7.0 -> v7.7.0
* [new tag] v7.7.1 -> v7.7.1
* [new tag] v7.7.2 -> v7.7.2
* [new tag] v7.8.0 -> v7.8.0

# 删除临时创建的Repository。
$ cd ..
$ rm -rf hexo-theme-next.git
# 或windows使用如下命令
> rmdir /s /q hexo-theme-next.git

设置提交的位置到镜像

1
2
$ cd repository-to-mirror
$ git remote set-url --push origin https://github.com/YaoHuanyu/mirror-themes-next

与bare clone一样,mirror clone包含所有远程分支和标记,但每次获取时都会覆盖所有本地引用,因此它始终与原始存储库相同。设置push的URL可以简化推送到镜像的过程。要更新镜像,获取更新并推送。

1
2
$ git fetch -p origin
$ git push --mirror