Git 使用教程

添加、修改、删除以及查看本地git的用户信息

全局

查看

git config --global user.name
git config --global user.email

修改

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

删除

git config --global --unset user.name "yourName"
git config --global --unset user.email "your@email.com"

查看全部信息

git config --list

本地(当前仓库)

全局的命令去掉 --global 即可变为当前仓库

其他

# 提示“warning: LF will be replaced by CRLF”的解决办法
git config --global core.autocrlf tru

# 删除源
git remote remove origin

# 增加源
git remote add origin ‘address’
git remote set-url origin ‘address’

# 推送到指定分支 develop
git push origin develop

# 回滚
git reset --hard XXXXXXX回滚到分支

# 强制推送到master分支,获取其它分支,自己修改
git push -f origin master

添加文件,并推送

添加到暂存区

git add .
  • . 代表所有文件

查看状态

git status

提交到仓库

git commit -m "初始化仓库"
  • -m 为 为了添加到暂存区(git add) 命令添加的文件设置操作介绍

添加远程仓库地址

git remote add origin https://github.com/vuejs/vue.git

查看远程仓库

git remote -v
git remote show origin

推送

git push origin master
  • 将 commit 和 git add 的内容推送到仓库。
  • -u,使用-u选项指定一个默认主机。git push后面加上参数

移除暂存区中的文件

使用 git rm 命令 删除暂存区指定文件

git rm --cached <file>
  • 将暂存区中的内容删除,工作区中对应的文件并不会受到影响。

使用 git reset HEAD 命令 撤销已被放入暂存区的文件

撤销暂存区指定文件(取消某一个文件的缓存)

git reset HEAD <file>

撤销暂存区所有文件(取消 git add 缓存的所有内容)

git reset HEAD .

使用 git restore 命令

取消某一个文件的暂存

git restore --staged <file>

取消所有已暂存的文件

git restore --staged .
  • 此命令将会将文件从暂存区移除,但保留在工作区中。

四下皆无人