1、git工作图
git总共分为以下几个部分
- workspace 工作区
- Index / Stage:暂存区
- Repository:仓库区(或本地仓库)
- Remote:远程仓库
2、新建
在当前目录新建一个Git代码库
git init
新建一个目录,将其初始化为Git代码库
git init <project name>
clone一个项目
git clone <remoteurl>
3、配置
git 的配置文件 .gitconfig
显示当前的Git配置
git config --list
编辑Git配置文件
git config -e [--global]
设置提交代码时的用户信息
git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"
4、增加、删除文件
增删改文件到暂存区
git add <file1> <file2> 添加多个文件
git add <dir> 添加目录,包括其子级目录
git add . 将当前目录的所有文件添加到暂存区
git add -p 添加每个变化前,都会要求确认
git rm <file1> <file2> 删除工作区文件,并且将这次删除放入暂存区
git rm --cached [file] 停止追踪指定文件,但该文件会保留在工作区
git mv [file-original] [file-renamed] 文件重命名
5、提交代码
git commit -m [message] 提交暂存区的所有文件到仓库区
git commit -m [file1] [file2] [message] 提交指定文件到仓库区
git commit -a 提交自上次commit之后的所有改动到仓库区
git commit -v 提交时显示所有diff信息
git commit --amend -m [message]
使用一次新的commit,替代上一次提交
如果代码没有任何新变化,则用来改写上一次commit的提交信息
重做上一次commit,并包括指定文件的新变化
git commit --amend [file1] [file2] ...