0%

git命令小结

前言:记录一下自己平时git命令的一些使用

git 官方文档 https://git-scm.com/book/zh/v2

git init

初始化,生成.git隐藏文件

git add

1
2
3
4
5
6
7
8
#会把本地所有untrack的文件都加入暂存区,并且会根据.gitignore做过滤,
git add .
# 会忽略.gitignore,把任何文件都加入
git add *
# 同git add .
git add -A
# 同git add .
git add --all

image-20200105182305052

这里说一个git文件状态,首先是untracked就是未追踪状态,这是文件尚没有进行版本控制,然后git add使该文件进入缓存区,然后commit提交到本地仓库(git是记录快照并保存这个快照的索引),最后push到远程仓库

git clone

克隆并下载仓库

1
2
3
4
5
6
# git协议
git clone git://xxx
# http协议
git clone http://xxx
# 指定分支名
git clone -b <name>

git commit

1
2
# 提交
git commit -m "注释"

git commit -am ‘注释’ 是下列两条命令的简写,

1
2
3
git add .

git commit -m "注释"

但是却发现不能将新增文件进行版本控制,如下图image-20200105175227745

发现了git commit -am ‘update’ 只能提交已经tracked即追踪过的文件,如果是新文件,必须使用分开的命令。

git remote

1
2
3
4
5
6
# 查看远程库信息
git remote
# 详细查看
git remote -v
# 本地关联远程库 origin是仓库名
git remote add origin 远程仓库地址

git rm

1
2
# 删除文件
git rm filename

git push

1
2
# 推送到远程仓库 origin是仓库名 master是分支名
git push origin master

git status

1
2
# 查看仓库当前的状态
git status
-------------本文结束感谢您的阅读-------------