git 常用命令
git init 初始化
git add filename 将单个文件添加到 版本库的暂存区
git add . 将当前目录中所有文件添加到 版本库的暂存区
git status 查看当前工作区状态
git commit -m '描述信息' 把文件从暂存区提交到分支(版本库的仓库)
git stash 将当前工作区所有修改的内容临时存储起来,并将工作区还原到当前版本未修改过的状态
git stash pop 将第一个记录从“某个地方”重新拿到工作区(可能有冲突)
git stash list 查看“某个地方”存储的所有记录
git stash clear 清空“某个地方”
git stash apply 编号, 将指定编号记录从“某个地方”重新拿到工作区(可能有冲突)
git stash drop 编号,删除指定编号的记录
git log 查看版本控制系统的历史纪录
git reset --hard 版本号 将工作区文件回滚到某一版本
git reflog 回滚后查看历史命令
git diff HEAD -- filename 查看工作区和版本库里面最新版本的区别:
git checkout -- filename 是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。
rm filename 删除文件
git branch branchname 创建分支
git branch 查看分支
git checkout branchname 切换分支
git merge branchname 将branchname分支合并到当前分支
git remote add origin https://github.com/hedeyong11/Practice.git 远程库设置别名origin
git clone origin https://github.com/hedeyong11/Practice.git 从远程仓库clone到本地
git push origin master 从本地库分支上传文件到远程仓库,pull=fetch+merge
git pull origin master 从远程仓库下拉文件到本地仓库
git fetch origin master 从远程分支下拉文件到本地库分支,相当于是从远程获取最新版本到本地,不会自动merge
branch相关常用命令:
git branch 分支名称 创建分支
git checkout 分支名称 切换分支
git branch -m 分支名称 创建并切换到指定分支
git branch 查看所有分支
git branch -d 分支名称 删除分支
git merge 分支名称 将指定分支合并到当前分支