常用命令总结
mkdir 创建目录
touch 创建文件
echo “111” 出输出内容
echo “111”>>>文件名 如果文件不存在则创建文件并写入内容 如果文件存在则追加内容
rm -rf 文件或作者目录 递归删除
cd 切换目录
pwd 查看当前所在位置
ll -a 查看所有文件包含隐藏文件 【a-all】
ll 查看所有文件
git init 初始化git仓库
git config --list 查看git配置
git log 查看提交日志
git status 查看仓库状态
git clone url 克隆一个远程仓库
如何创建一个git仓库 git init
mkdir demo_01
cd demo_01
git init
如何不让git管理
rm -rf .git
查看初始化给git仓库的状态
echo “1111”>>1.txt
git status
on branch master //主分支
no commits yet //还没有承诺
untracked files: //为追踪
//需要使用git add 文件名 将数据提交到暂存区
(use “git add …” to include in what will be committed)
1.txt
//除了存在未追踪的文件外,没有添加任何内容以提交(使用“git add”跟踪)
nothing added to commit but untracked files present (use “git add” to track)
查看将数据提交到暂存区后的状态
git add.
git status
=========
on branch master //主分支
no commits yet //还没有承诺
changes to be committed: //要提交的更改
//如果想将暂存区的内容移回到工作区 需要使用 git rm --cached 文件名
(use “git rm --cached …” to unstage)
new file: 1.txt
//新文件 1.txt
查看将暂存区的数据提交到版本库之后的仓库状态
git commit -m "v1.0"
[master (root-commit) 454342134] v1.0 //【主(跟提交) 454342134】 v1.0
1 file changed, 1 insertion(+) //1个文件更改,1个插槽(+)
create mode 100644 1.txt //创建模式100644 1.txt
git status
on brach master
nothing to commit,working tree clean //没有问题了
配置 参数选项
--global 修改全局配置文件 -git config
--system 修改所有用户的配置文件
--local 修改本地仓库配置
设置配置
git config 参数选项 键、值
查看配置
git config --list
查看指定数据配置
git config 键
设置别名
gir config 参数选项 alias. 别名 起别名的指令 (没熟练掌握命令之前 别乱玩)
git 的三个区域
工作区 --在工作区中参数或创建某些文件
暂存区 --对已存在的文件做一个快照,保存到暂存区
git add file
版本库 --将保存在暂存区的数据提 交给版本库
git commit -m "版本名"
版本名过长 或者描述内容过长
git commit 进入里面进行编辑
查看提交历史 git log
git log -n 查看最后n条数据
git log -p 或 --patch 显示了每次提交中引入的差异
git log --stat 想查看每次提交的一些简短统计信息
git log --pretty=format:"%h - %an, %ar :%s"
//版本号 - 用户名,多久以前提交到:版本名称
1533a52 - F_Miao, 5 minutes ago : V3.0
b34a405 - F_Miao, 8 minutes ago : V2.0
5cbcc6c - F_Miao, 31 minutes ago : V1.0
分支基础操作
创建分支 git branch 分支名称
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git branch test
fatal: Not a valid object name: ‘master’.
原因:没有提交一个对象,要先commit之后才会真正简历master分支,此时才可以建立其他分支。
git add.
git commit -m “注释内容”
重新git branch tes 即可
测试1
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git add .
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git commit -m "V2.0"
[master 1afd910] V2.0
4 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 3.txt
create mode 100644 4.txt
create mode 100644 5.txt
create mode 100644 6.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git branch test
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git branch
* master
test
查看分支 git branch
$git branch
master
test
分支名称前有代表当前所在分支
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_05 (test)
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_05 (master)
切换分支 git checkout 分支名称
删除分支 git branch -d 分支名称
$ git branch
* master
testing
$ git branch -d testing
Deleted branch testing (was 85fc7e7).
$ git branch
* master
合并分支 git merge 分支名称
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (aaa)
$ git checkout master
Switched to branch 'master'
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git merge aaa
Updating b0b19b1..5153393
Fast-forward
0.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 0.txt
ti'jiao'geng'xin'zhi'hou
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ ls
0.txt 1.txt 3.txt 4.txt 5.txt 6.txt 8.txt
合并冲突
git status 与 git diff 的区别
git status 显示你上次提交你上次更新之后所更改或者写入缓存的改动
git diff 遗憾一行的显示这些改动具体是啥
git diff 查看差异
git rest HEAD 文件名,将缓存内容移除缓存
//将两个缓存区的文件取消一个查看
$ git status -s //查看仓库数据的状态
?? 1.txt
?? 3.txt
?? 4.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git add 1.txt //提交到缓存区
warning: LF will be replaced by CRLF in 1.txt.
The file will have its original line endings in your working directory
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git status -s //查看仓库数据状态
A 1.txt
?? 3.txt
?? 4.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git add .
warning: LF will be replaced by CRLF in 3.txt.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in 4.txt.
The file will have its original line endings in your working directory
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git status -s
A 1.txt
A 3.txt
A 4.txt
//将3.txt从暂存区移除
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git reset HEAD -- 3.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git status -s
A 1.txt
A 4.txt
?? 3.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: 1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
2.txt
3.txt
4.txt
5.txt
6.txt
git rm 将文件从暂存区中移除
git rm 文件名 将文件从暂存区 与 工作区移除
git rm --cached 文件名 将文件从暂存区中移除 保留工作区
测试1:
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git rm 1.txt
// 错误:以下文件在索引中已暂存更改:
error: the following file has changes staged in the index:
1.txt
//(使用--cached保存文件,或使用-f强制删除)
(use --cached to keep the file, or -f to force removal)
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git rm -f 2.txt //从将2.txt从工作区与暂存区移除
rm '2.txt'
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git status -s
A 1.txt
A 3.txt
?? 4.txt
?? 5.txt
?? 6.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ ls -a
./ ../ .git/ 1.txt 3.txt 4.txt 5.txt 6.txt
测试2:
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git rm --cached 3.txt //将3.txt文件从暂存区移至工作区
rm '3.txt'
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ git status -s
A 1.txt
?? 3.txt
?? 4.txt
?? 5.txt
?? 6.txt
xiaoxiaopi@CD50 MINGW64 /c/课堂代码/课堂代码/git/demo_06 (master)
$ ls -a
./ ../ .git/ 1.txt 3.txt 4.txt 5.txt 6.txt
git mv
git mv 命令做的所有事情就是 git rm --cached,
重命名磁盘上的文件,然后再执行 git add 把新文件添加到缓存区。
因此,虽然有 git mv 命令,但它有点多余
git log 查看提交历史
有什么问题大家可以留言哦!