作为分布式版本控制系统的代表git和github已经成为大多数开发人员首选版本控制工具。由于其不同与SVN的集中式版本管理,因此在协同工作时的方式略有不同,下面让我们来对比分析一下(这里以本人的DICOM3.0标准中文版开源书籍为例):
F:\GitTest\zssuretest\DICOM-Chinese>git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
F:\GitTest\zssuretest\DICOM-Chinese>git remote -v
origin https://github.com/zssure-test/DICOM-Chinese.git (fetch)
origin https://github.com/zssure-test/DICOM-Chinese.git (push)
other git@github-test:zssure-test/DICOM-Chinese (fetch)
other git@github-test:zssure-test/DICOM-Chinese (push)
zssure-thu-origin https://github.com/zssure-thu/DICOM-Chinese.git (fetch)
zssure-thu-origin https://github.com/zssure-thu/DICOM-Chinese.git (push)
F:\GitTest\zssuretest\DICOM-Chinese>git pull
Already up-to-date.
F:\GitTest\zssuretest\DICOM-Chinese>git remote -v
origin https://github.com/zssure-test/DICOM-Chinese.git (fetch)
origin https://github.com/zssure-test/DICOM-Chinese.git (push)
other git@github-test:zssure-test/DICOM-Chinese (fetch)
other git@github-test:zssure-test/DICOM-Chinese (push)
zssure-thu-origin https://github.com/zssure-thu/DICOM-Chinese.git (fetch)
zssure-thu-origin https://github.com/zssure-thu/DICOM-Chinese.git (push)
F:\GitTest\zssuretest\DICOM-Chinese>git remote add kuangbi-mnhwa https://github.com/mnhwa/DICOM-Chinese.git
F:\GitTest\zssuretest\DICOM-Chinese>git remote -v
kuangbi-mnhwa https://github.com/mnhwa/DICOM-Chinese.git (fetch)
kuangbi-mnhwa https://github.com/mnhwa/DICOM-Chinese.git (push)
origin https://github.com/zssure-test/DICOM-Chinese.git (fetch)
origin https://github.com/zssure-test/DICOM-Chinese.git (push)
other git@github-test:zssure-test/DICOM-Chinese (fetch)
other git@github-test:zssure-test/DICOM-Chinese (push)
zssure-thu-origin https://github.com/zssure-thu/DICOM-Chinese.git (fetch)
zssure-thu-origin https://github.com/zssure-thu/DICOM-Chinese.git (push)
F:\GitTest\zssuretest\DICOM-Chinese>git branch -v
* master bb0d864 Merge branch 'master' of https://github.com/zssure-test/DICOM-Chinese
F:\GitTest\zssuretest\DICOM-Chinese>git fetch kuangbi-mnhwa
remote: Counting objects: 14, done.
remote: Total 14 (delta 0), reused 0 (delta 0), pack-reused 14
Unpacking objects: 100% (14/14), done.
From https://github.com/mnhwa/DICOM-Chinese
* [new branch] master -> kuangbi-mnhwa/master * [new branch] pr/1 -> kuangbi-mnhwa/pr/1
F:\GitTest\zssuretest\DICOM-Chinese>git checkout -b part5-kuangbi kuangbi-mnhwa/master
Branch part5-kuangbi set up to track remote branch master from kuangbi-mnhwa.
Switched to a new branch 'part5-kuangbi'
F:\GitTest\zssuretest\DICOM-Chinese>git branch -v
master bb0d864 Merge branch 'master' of https://github.com/zssure-test/DICOM-Chinese
* part5-kuangbi 7c23aba 6.1.2.5----6.1.3
F:\GitTest\zssuretest\DICOM-Chinese>git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
F:\GitTest\zssuretest\DICOM-Chinese>git branch -v
* master bb0d864 Merge branch 'master' of https://github.com/zssure-test/DICOM-Chinese
part5-kuangbi 7c23aba 6.1.2.5----6.1.3
F:\GitTest\zssuretest\DICOM-Chinese>git merge part5-kuangbi
Merge made by the 'recursive' strategy.
Figure/Part 5/PS3.5_Table 6.1_1.jpg | Bin 0 -> 131815 bytes
...t 5\357\274\232Data Structures and Encoding.md" | 353 +++++++++++++++++++++ 2 files changed, 353 insertions(+) create mode 100644 Figure/Part 5/PS3.5_Table 6.1_1.jpg create mode 100644 "Part 5\357\274\232Data Structures and Encoding.md"
F:\GitTest\zssuretest\DICOM-Chinese>git status
On branch master
Your branch is ahead of 'origin/master' by 5 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
F:\GitTest\zssuretest\DICOM-Chinese>git push origin
Username for 'https://github.com': zssure-test
Password for 'https://[email protected]':
Counting objects: 19, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (16/16), 123.50 KiB | 0 bytes/s, done.
Total 16 (delta 6), reused 0 (delta 0)
To https://github.com/zssure-test/DICOM-Chinese.git
bb0d864..63368d4 master -> master
F:\GitTest\zssuretest\DICOM-Chinese>
之前在系列博文DICOM:DICOM中文版开源书籍协同编辑之“Github Pull Requests”已经介绍过使用Github提供的Pull Requests来实现多人协同编辑的具体步骤,这里就不详细介绍了,大致说一下操作流程,具体示例请阅读之前的博文。
git clone [email protected]:zssure-test/DICOM-Chinese.git
git config user.name "zssure-test"
git config user.email "[email protected]"
git config --local
#此处任意修改README.md的内容
git status #查看修改状态
git add . #添加所有修改
git commit -m "zssure git bash test" #提交修改到本地仓库
git push origin master #push修改到github
上面提到的合并他人仓库,用于自己主动将他人的修改合并到自己的仓库中;请求他人合并自己的修改,用于将自己的修改同步给组内其他人员,主要是用于将自己的修改提价到一个公共的仓库中,作为最终的发版库。
通过上述两种基本可以完成多人协作工作,当然在具体应用过程中还会遇到回滚、冲突、撤销等问题,后续会继续给出实际应用过程中的示例。
作者:[email protected]
时间:2015-10-10