Git简单命令列表

初始化

初始化本地空版本库,仓库,英文名repository
mkdir test && cd test
git init
克隆项目到本地
git clone <url>

远程同步操作

关联远程仓库和本地仓库
git remote add <shortname> <url>
提交本地仓库到远程仓库
git push [-u] <remote> <branch>
列出所有远程仓库关联
git remote -v
重新关联远程仓库和短名
git remote set-url <shortname> <url>

分支操作

创建分支
git branch <branchName>
切换分支
git checkout <branchName>
以上两条相当于
git checkout -b <branchName>
列出所有分支
git branch
合并分支到当前分支
git merge <branchName>
删除分支
git branch -d <branchName>

本地操作

更新修改到暂存区
git add <file>
删除暂存区文件
git rm --cache <file>
提交暂存区修改
git commit -m "message" [file]
放弃工作区指定文件的操作
git checkout -- <file>
暂存区与分支指定的版本同步
git reset <commit> [file]
同步工作区和暂存区到相应版本
git reset --hard <commit>

查询操作

查看暂存区状态
git status
查看提交日志
git log
查看操作
git reflog

保存现场

切换分支前保存工作区现场
git stash
列出保存的工作去现场
git stash list
删除保存的工作区现场
git stash drop
恢复并删除保存的工作区现场
git stash pop

配置

增加显示颜色
git config --global color.ui true
忽略文件
.gitignore #注释
增加命令别名
git config --global alias.name 'command'
修改用户名邮箱
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

猜你喜欢

转载自blog.csdn.net/xuejianbest/article/details/84858510