配置操作

全局配置

对全局用户的所有仓库有效(最常用)
git config --global user.name '你的名字'  
git config --global user.email '你的邮箱'

对当前仓库用户有效(不常用)
git config --local user.name '你的名字'
git config --local user.email '你的邮箱'

对系统所有用户有效(根本就不用)
git config --system user.name '你的名字'
git config --system user.email '你的邮箱'


--------------------------例如--------------------------

git config --global user.name ''
git config --global user.email ''
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

起别名

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
  • 1.
  • 2.
  • 3.
  • 4.

清除设置

git config --unset --global 要删除的全局配置项
git config --unset --local  要删除的当前仓库配置项
git config --unset --system 要删除的系统配置项

--------------------------例如--------------------------
git config --unset --global user.name
git config --unset --global user.email
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

查看配置

git config --list           查看当前配置
git config --list --global  查看全局配置
git config --list --local   查看当前仓库配置
git config --list --system  查看系统配置
  • 1.
  • 2.
  • 3.
  • 4.

初始化仓库

cd 项目代码所在的文件夹
git init
  • 1.
  • 2.

建立客户端与远程服务端的连接

git remote add origin 远程仓库的地址

--------------------------例如--------------------------
git remote add origin git@server-name:path/repo-name.git
  • 1.
  • 2.
  • 3.
  • 4.

本地操作

查看变更情况

git status
  • 1.

git add , git add -A , git add -u

git add .   git add -A   git add -u
  • 1.

将指定文件添加到暂存区

git add 文件1 文件2 文件3
  • 1.

直接将修改后的文件提交到本地仓库

git commit -a -m "说明信息"   或者   git commit -am "说明信息"
  • 1.

变更文件名

git mv 原文件名 新修改后的文件名
  • 1.

查看当前目录下的所有文件

ls -al 
  • 1.

比较工作区和暂存区的所有差异

git diff
  • 1.

比较某个文件在工作区和暂存区的差异

git diff 文件
  • 1.

比较暂存区和 HEAD 的所有差异

git diff --cached
  • 1.

比较某个文件在暂存区和 HEAD 的差异

git diff --cached 文件
  • 1.

查看所有提交记录

git log
  • 1.

查看显示就近的 n 个 commit

git log -n
  • 1.

当前分支 commit 用一行显示,该命令会使commitID变的简短

git log --oneline
  
或者  

git log --pretty=oneline --abbrev-commit 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

当前分支各个 commit 用一行显示,commitID 比较长

git log --pretty=oneline
  • 1.
查看commit之间的父子关系
git log --pretty=raw 
git log --pretty=raw --abbrev-commit   //缩短commitId
  • 1.
  • 2.

可以看到分支合并图

git log --graph --pretty=oneline 
  • 1.

显示所有本地和远程的所有提交记录

git reflog
  • 1.

查看所有分支的历史

git log --all 
  • 1.

查看图形化的 log 地址

git log --all --graph
  • 1.