git命令总结
[toc]
1.git简介
1.1 git工作流程
1.2 git四种状态
2.git命令总结
2.1 git工作区域及文件颜色
git status 文件三种颜色的变化
红色- 新增文件或者 修改的旧文件-->执行命令
git add .
或者git add 文件名
- git已经管理起来的文件-->执行命令
git commit -m '描述信息'
白色
- 已经生成版本的文件
2.2 git提交数据
创建文件
$ touch aaa bbb
查看git文件状态(此时文件是红色的,属于新增文件)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
aaa
bbb
nothing added to commit but untracked files present (use "git add" to track)
提交文件至暂存区
$ git add .
此时再查看文件,文件是绿色的,已被git管理起来
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: aaa
new file: bbb
2.3 git删除数据
2.3.1 git删除暂存区中的文件 git rm --cached
git删除暂存区中的文件
$ git rm --cached aaa bbb
rm 'aaa'
rm 'bbb'
此时文 件变回红色
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
aaa
bbb
nothing added to commit but untracked files present (use "git add" to track)
2.3.2 git删除工作区和暂存区中的文件 git rm -f 文件名
查看暂存区中的文件,此时是绿色的
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: aaa
new file: bbb
删除工作区的文件同时暂存区中的文件也会同时被删除
$ git rm -f aaa bbb
rm 'aaa'
rm 'bbb'
$ ls
$ git status
On branch master
nothing to commit, working tree clean
2.4 git移动数据
2.4.1 git提交数据至版本库 git commit -m '描述信息'
创建文件
$ touch aaa bbb
提交文件至暂存区
$ git add .
此时文件是绿色的
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: aaa
new file: bbb
提交文件至版本库
$ git commit -m 'touch aaa bbb'
[master 7215e51] touch aaa bbb
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 aaa
create mode 100644 bbb
此时再查看文件暂存区中已经没有了,已经被git管理起来了
$ git status
On branch master
nothing to commit, working tree clean
2.4.2 git移动数据,有时会将已经添加至暂存区的文件重命名 git mv 原文件 新文件
此时文件是绿色的
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: aaa
new file: bbb
现在想把暂存区中的文件 aaa
修改为 AAA
$ git mv aaa AAA
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: AAA
new file: bbb
提交文件至git版本库
$ git commit -m 'change file aaa->AAA'
[master 7de2d02] change file aaa->AAA
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 AAA
create mode 100644 bbb