新建文件夾
[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)
參考文件: