2017-06-23 20:06:13
版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统。 - Git官方
版本控制的价值
如RCS

如SVN、ClearCase、VSS、CVS

如Git、BitKeeper、Mercurial

| 方面 | 本地式 | 集中式 | 分布式 |
|---|---|---|---|
| 速度 | 快 | 慢 | 快 |
| 网络要求 | 不需网络,离线 | 提交需联网 | 支持离线 |
| 灵活性 | 无法无天 | 集中式工作流 | 支持多工作流:parnter或集中式 |
| 数据完整性 | 易缺损 | 元数据可能缺失 | 按元数据方式存储,最完整 |
| 并行协作 | 难 | 一般 | 易 |
| 学习曲线 | 上手快 | 上手快 | 有一定学习曲线 |
| 应用场景 | 个人项目 | 企业项目 | 开源项目 |

到Git官网,找到操作系统对应的安装文件/指导,执行安装
全局(--global)设置用户名和email
$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com

Tools -> Global options -> Git Executable

Tools -> Project options -> 启用git


git clonegit addgit mvgit rmgit branchgit checkoutgit commitgit fetch / git pullgit push
cd <共享路径>/TestRepo # 伪代码 git init --bare

git clone <共享路径>/TestRepo

git checkout -b work

git checkout master
git branch -d work
Bash
$ git status
On branch work
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README
Untracked files:
(use "git add <file>..." to include in what will be committed)
note.txt
GUI

git add则添加跟踪。git log查看提交历史$ git add *
$ git commit -m "add note.txt"
[Work a50dba4] add note.txt
2 files changed, 1 insertions(+)
create mode 100644 note.txt
$ git log
commit 42e62ea88fddc...57bc9a (HEAD -> work)
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:03:52 2017 +0800
add note.txt
commit add2d1ec93d...3637c2 (origin/master, master)
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:02:17 2017 +0800
init
echo $'hotfix 1:\r\n' > note.txt echo $'\t1. Foo.\r\n\t2. Bar.' >> note.txt git add . git commit -m "hotfix 1" git tag -a "v1.0" -m "Ver 1.0" echo $'\r\nhotfix 2:\r\n' >> note.txt echo $'\t1. Ti.\r\n\t2. Da.' >> note.txt git add . git commit -m "hotfix 2" echo $'\r\nhotfix 3:\r\n' >> note.txt echo $'\t1. Ha.\r\n\t2. HaHa.' >> note.txt git add . git commit -m "hotfix 3" git log --all
$ git log
commit 8aea41c3...0b4bc3 (HEAD -> work)
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:09:23 2017 +0800
hotfix 3
commit 79784f72...203665e
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:09:18 2017 +0800
hotfix 2
commit 4fd9edc7e...58d2f1 (tag: v1.0)
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:08:59 2017 +0800
hotfix 1
commit 42e62ea88fddc9...5c57bc9a
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:03:52 2017 +0800
add note.txt$ git checkout v1.0 HEAD is now at 4fd9edc... hotfix 1
$ vi note.txt
hotfix 1:
1. Foo.
2. Bar.$ git reset --mixed 42e62ea Unstaged changes after reset: M note.txt
$ git log
commit 42e62ea88f...bc9a (HEAD -> work)
Author: John Doe <john.doe@example.com>
Date: Fri Jun 23 15:03:52 2017 +0800
add note.txt
git add. git commit -m "hotfix 1-3" git tag -f "v1.0" -m "Ver 1.0"
git checkout work git push -u
相当于
git push origin work
如共享仓库并没有work分支,需要设定远程上游
git push --set-upstream origin work
git merge)git checkout work git fetch
git pull
git diff 查看不同分支的差异$ git diff master work diff --git a/README b/README index e69de29..4baf047 100644 --- a/README +++ b/README @@ -0,0 +1 @@ +Hello world. \ No newline at end of file diff --git a/note.txt b/note.txt new file mode 100644 index 0000000..0de80fa --- /dev/null +++ b/note.txt @@ -0,0 +1,14 @@ +hotfix 1: + + 1. Foo. + 2. Bar. :
git merge合并分支$ git merge master work Updating add2d1e..6060ff4 Fast-forward README | 1 + note.txt | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 note.txt
Thank you!