配置用户名,邮箱,创建用于存放Git仓库的目录
g@g-PC MINGW64 /
$ git config --global user.name "heming"
g@g-PC MINGW64 /
$ git config --global user.email "15210251075@163.com"
g@g-PC MINGW64 /
$ mkdir learngit
g@g-PC MINGW64 /learngit
$ pwd
/learngit
初始化Git仓库
g@g-PC MINGW64 /learngit
$ git init
Initialized empty Git repository in D:/Program Files/git/Git/learngit/.git/
# 空的仓库(empty Git repository)
g@g-PC MINGW64 /learngit (master)
$ ls -ah
./ ../ .git/
添加文件到Git目录下
g@g-PC MINGW64 /learngit (master)
$ cat readme.txt
Git is a version control system.
Git is free software.
添加文件到Git仓库,操作顺序是先add,再commit,同时加上说明-m
g@g-PC MINGW64 /learngit (master)
$ git add readme.txt
g@g-PC MINGW64 /learngit (master)
$ git commit -m "wrote a readme file"
[master (root-commit) 311bbf5] wrote a readme file
1 file changed, 2 insertions(+)
create mode 100644 readme.txt
修改Git仓库中的文件,修改完毕后,也是先add,再commit,同时加上说明-m
#第一次修改
g@g-PC MINGW64 /learngit (master)
$ git add readme.txt
g@g-PC MINGW64 /learngit (master)
$ git commit -m "append GPL"
[master c3528d1] append GPL
1 file changed, 3 insertions(+), 1 deletion(-)
#第二次修改
g@g-PC MINGW64 /learngit (master)
$ git add readme.txt
g@g-PC MINGW64 /learngit (master)
$ git commit -m "del 2 rows"
[master 932f121] del 2 rows
1 file changed, 2 deletions(-)
git log命令查看从最近到最远的提交日志。如果嫌输出信息太多,看得眼花缭乱的,可以试试加上--pretty=oneline参数,commit id(版本号)是一个SHA1计算出来的一个非常大的数字,用十六进制表示
g@g-PC MINGW64 /learngit (master)
$ git log #查看提交日志
commit 932f121b72208b5cd526f86c50fe8cd195cf31ce (HEAD -> master)
Author: heming <15210251075@163.com>
Date: Wed Jan 3 15:06:29 2018 +0800
del 2 rows
commit c3528d11bd64debdc7cc629b5e30ae1e44109a73
Author: heming <15210251075@163.com>
Date: Wed Jan 3 15:05:32 2018 +0800
append GPL
commit 311bbf533910c65b3df3328bd4148e52a3ceb6c0
Author: heming <15210251075@163.com>
Date: Wed Jan 3 15:01:24 2018 +0800
wrote a readme file
g@g-PC MINGW64 /learngit (master)
$ git log --pretty=oneline #每一次修改只记作一行
932f121b72208b5cd526f86c50fe8cd195cf31ce (HEAD -> master) del 2 rows
c3528d11bd64debdc7cc629b5e30ae1e44109a73 append GPL
311bbf533910c65b3df3328bd4148e52a3ceb6c0 wrote a readme file
网友评论