git常用命令总结
git的安装
git设置用户信息
# 查看基础信息
$ git config -l
# 设置用户名
$ git config --global user.name " "
# 设置用户邮箱
$ git config --global user.email " "
# 查看用户名
$ git config user.name
# 查看用户邮箱
$ git config user.email
# 删除文件
$ git rm
# 移动文件/重命名
$ git mv
查看版本号
$ git version
建立git库
# 初始化文件夹,在当前文件夹下生成.git文件夹,包含所有git操作需要的东西,用于管理git仓库
$ git init
# 查看远程仓库
$ git remote
# 显示仓库的详细信息
$ git remote -v
# 删除仓库
$ git remote rm <远程仓库名字>
查看本地分支
# *号标记当前分支
$ git branch
$ git branch -v
切换本地分支
$ git checkout [分支名]
合并分支
$ git merge [分支名]
查看当前文件夹状态
$ git status
查看文件更改内容
#加入暂存区之前
$ git diff
#加入暂存区之后
$ git diff --cached
添加文件到暂存区
#提交之前将新添加或者有更改的文件加入git的暂存区,git add ./*为添加当前目录的所有文件
$ git add <文件名>
撤销对文件的更改
#文件加入暂存区之前
$ git checkout -- <file>
#文件加入暂存区之后
$ git reset HEAD <file>
$ git checkout -- <file>
提交暂存区文件
$ git commit
#引号内填写备注信息
$ git commit -m " "
查看提交历史
$ git log
上传文件
#把本地分支合并到远程仓库的指定分支
$ git push <库> <分支>
下拉文件
#把远程仓库的分支合并到本地分支
$ git pull <库> <分支>
克隆文件
#通过远程的url把对应的文件夹克隆到本地
$ git clone <url>
git pull 拉取提示错误
error: Your local changes to the following files would be overwritten by merge: protected/config/main.php
Please, commit your changes or stash them before you can merge.
解决方法:
- 服务器代码合并本地代码
$ git stash //暂存当前正在进行的工作。
$ git pull origin master //拉取服务器的代码
$ git stash pop //合并暂存的代码
- 服务器代码覆盖本地代码
$ git reset --hard //回滚到上一个版本
$ git pull origin master