教程来自: Git教程(廖雪峰的官方网站)
学习Git的基本内容,对教程内容进行理解并脱水
1. Git简介
2. 安装Git
1. ubuntu上安装Git
$ sudo apt-get install git
2. 配置Git: 为你在本地的所有repo指定用户名和邮箱
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
其中'Your Name'为用户名,'email@example.com'为Email地址.
3. 创建版本库: 创建新的代码仓库(repository)
1. 建立空目录
$ mkdir learngit
$ cd learngit
2. 以当前目录为repo目录初始化repo
$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
3. 为repo添加文件
3.1. 新建文件readme.txt
Git is a version control system.
Git is free software.
3.2. 使用git add命令将文件提交到repo
$ git add readme.txt
3.3. 使用命令git commit将文件提交到repo (-m 参数后是提交版本说明,要好好写,不然以后很容易混乱)
$ git commit -m "wrote a readme file"
[master (root-commit) cb926e7] wrote a readme file
file changed, insertions(+)
create mode readme.txt
在没有commit之前所有add的内容都不会提交到repo.
4. 时光机穿梭(好中二的名字..)
4.1. 在修改了readme.txt之后
Git is a distributed version control system.
Git is free software.
4.2. 运行git status可以查看当前repo的状态
$ git status
# On branch master
# 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
4.3. 也可以使用git diff * 查看被修改文件的具体修改内容
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6
--- a/readme.txt
+++ b/readme.txt
@@ -, +, @@
-Git is a version control system.
+Git is a distributed version control system.
Git is free software.
4.4 再使用add和commit命令将修改提交到repo
$ git add readme.txt
$ git commit -m "add distributed"
[master ea34578] add distributed
file changed, insertion(+), deletion(-)
使用git status可以查看目录中文件被修改,文件已添加和文件已提交的不同状态.