- 安装完成后,还需要最后一步设置,在命令行输入:
$ git config --global user.name "Allen Zhong"
$ git config --global user.email "zhongyu211@126.com"
- git init
Initialized empty Git repository in /Users/michael/learngit/.git/
一定要放到learngit目录下(子目录也行),因为这是一个Git仓库,放到其他地方Git再厉害也找不到这个文件。
和把大象放到冰箱需要3步相比,把一个文件放到Git仓库只需要两步。
- 用命令git add告诉Git,把文件添加到仓库:
$ git add readme.txt
执行上面的命令,没有任何显示,这就对了,Unix的哲学是“没有消息就是好消息”,说明添加成功。
- 用命令git commit告诉Git,把文件提交到仓库:
#This command is very useful for it can totally replace the git bub repository
$ git commit -m -a "wrote a readme file"
[master (root-commit) cb926e7] wrote a readme file
1 file changed, 2 insertions(+)
create mode 100644 readme.txt
运行git status命令看看结果:
- 使用 git status 查看结果
$ 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")
- 使用 git diff 查看文件变化
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
Git is free software.
- ronglian@linux-99kl:~> git remote add origin https://github.com/zhongyu211/guangda.git
ronglian@linux-99kl:~> git remote -v
origin https://github.com/zhongyu211/guangda.git (fetch)
origin https://github.com/zhongyu211/guangda.git (push)
- git push -f