Git的基本原理与常用命令[二]

时间:2021-08-11 06:38:26

标签(linux): git

笔者Q:972581034 交流群:605799367。有任何疑问可与笔者或加群交流

git 的四个区域

Git的基本原理与常用命令[二]

四种状态

Git的基本原理与常用命令[二]

常用命令

git add                #加入暂存(索引区)
git status #查看状态
git status -s #状态概览
git diff #尚未暂存的文件
git diff --staged #暂存区文件
git commit #提交更新
git reset #回滚
git rm #从版本库中移除
git rm --cached README #从暂存区中移除
git mv #相当于mv git rm git add

查看历史版本

[root@git test]# git log
commit 1cf6888d97b0a361a3daed01a06c67936bc4f241
Author: chentiangang <chentiangang@yoho8.com>
Date: Thu Aug 17 23:49:27 2017 +0800 first index:v2 commit 145b100cd0e07a9e59e15cf71aad3338ed8a57a6
Author: chentiangang <chentiangang@yoho8.com>
Date: Thu Aug 17 23:42:32 2017 +0800 index.html

创建一个新的文件

[root@git test]# echo "news" > news.html
[root@git test]# ls
index.html news.html pay.html
[root@git test]# git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) new file: pay.html Untracked files:
(use "git add <file>..." to include in what will be committed) news.html

删除刚才提交到暂存区的文件

[root@git test]# git rm --cached pay.html
rm 'pay.html'
[root@git test]# git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed) news.html
pay.html nothing added to commit but untracked files present (use "git add" to track)