Git常用命令清单
2016-12-14 18:39
441 查看
创建
在指定目录创建工作仓库,未指定时在当前目录git init [dir]
创建不包含工作区的仓库
git init --bare
克隆远程仓库到本地
git clone url
配置
git config --global user.name ""git config --global user.email ""
git config --global core.editor vim
仓库
显示仓库基本信息git remote -v
显示仓库详细信息
git remote show repo-name
修改仓库名
git remote rename old new
修改/设置仓库地址
git remote set-url repo-name newurl oldurl
分支
创建新分支git branch new-branch [base-branch]
切换分支
git checkout branch-name
创建新分支并切换
git checkout -b new-branch [base-branch]
与远程分支同步
git pull origin origin-branch:local-branch -u
git push origin local-branch:origin-branch -uf
-u参数表示设置为自动跟踪,此后可直接使用git pull/push
-f参数强制覆盖
查看本地分支
git branch
查看远程分支
git branch -r
查看所有分支
git branch -a
删除分支
git branch -d branch-name
强制删除
git branch -D branch-name
删除远程分支
git push origin --delete branch-name
git push origin :origin-branch-name #冒号前为空格
提交
添加至暂存区git add .
提交至仓库
git commit -m "msg"
覆盖上次提交
git commit --amend -m "msg"
合并
合并目标分支和当前分支,不影响历史git merge tagget-branch --no-ff
--no-ff强制生成新提交
合并目标分支和当前分支,影响历史提交
git rebase target-branch -i
-i交互式合并,合并过程可见
冲突
使用merge时出现冲突,统一解决后重新
commit。
使用
rebase时出现冲突逐个解决,
执行
git rebase --continue继续合并,
执行
git rebase --abort退出合并。
回退
回退至commit-num,包含暂存区git reset commit-num
回退至commit-num,包含工作区和暂存区
git reset --hard commit-num
撤销工作区的修改,与暂存区表示一致
git checkout .
最近操作
git reflog
stash
保存当前修改git stash
恢复最新
git stash pop
显示所有
git stash list
blame
查看文件最后修改git blame file
标签
显示所有标签git tag
新建一个标签
git tag name
推送至远程仓库
git push origin --tags