新建文件夹
[root@localhost home]# mkdir gittest [root@localhost home]# cd gittest [root@localhost gittest]#
git初始化
[root@localhost gittest]# git init Initialized empty Git repository in /home/gittest/.git/
修改用户名和邮件
[root@localhost gittest]# git config user.name "Leon Nan" [root@localhost gittest]# git config user.email [email protected]
创建文件
[root@localhost gittest]# echo "init file" >> README [root@localhost gittest]# cat README init file
此时文件处在“Untracked”状态,即不受git管理,未被追踪的状态。可通过git status查看
[root@localhost gittest]# git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track)
添加文件,使文件接受git的管理
git add -A 将所有文件加入到索引库中
git add README 仅增加README文件
[root@localhost gittest]# git add README
此时文件处在“staged”状态,对文件进行了快照,保存在暂存区域,尚未交付到git仓库中。
[root@localhost gittest]# git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README #
交付文件,将保存在暂存区域的快照永远保存到git仓库中。
[root@localhost gittest]# git commit -m "init file" [master (root-commit) 7c4a592] init file 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 README
查看git状态及log
[root@localhost gittest]# git status # On branch master nothing to commit (working directory clean) [root@localhost gittest]# git log commit 7c4a592e4221c349dfad6dbda3f4056d47360191 Author: Leon Nan <[email protected]> Date: Mon Oct 10 03:07:26 2016 +0800 init file
修改文件
[root@localhost gittest]# echo "modify file" >> README [root@localhost gittest]# [root@localhost gittest]# [root@localhost gittest]# cat README init file modify file
此时文件处在modified状态
[root@localhost gittest]# git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README # no changes added to commit (use "git add" and/or "git commit -a")
添加文件,再次commit
[root@localhost gittest]# git add -A [root@localhost gittest]# git commit -m "modify file" [master 3bb3528] modify file 1 files changed, 1 insertions(+), 0 deletions(-)
查看文件log
[root@localhost gittest]# git log commit 3bb352807d3dddef1efd88a60805b6e09fb16ae1 Author: Leon Nan <[email protected]> Date: Mon Oct 10 03:33:35 2016 +0800 modify file commit 7c4a592e4221c349dfad6dbda3f4056d47360191 Author: Leon Nan <[email protected]> Date: Mon Oct 10 03:07:26 2016 +0800 init file [root@localhost gittest]# git status # On branch master nothing to commit (working directory clean)
参考文件: