git 配置
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
创建版本库
$ git init
查看状态
$ git status
添加所有文件
$ git add .
把文件提交到仓库 -m '' 说明 备注
git commit -m ''
推送到仓库
git push
拉取
git pull
克隆
git clone + 地址
查看difference
$ git diff
查看历史提交
git log
更新远程跟踪分支
git fetch origin
查看所有分支
git branch -a
创建并切换到dev分支
$ git checkout -b <name>
创建分支
$ git branch <name>
查看当前分支
$ git branch
切换分支
git checkout <name>
合并指定分支到当前分支
$ git merge <name>
撤销合并分支
git merge --abort
删除分支
git branch -d <name>
查看命令历史
git reflog
回退到上一个版本
$ git reset --hard HEAD^
回退到某一个版本 + commit id
$ git reset --hard commit id
记住git账号密码
git config --global credential.helper store
保存当前代码
git stash
恢复保存代码
git stash pop
从当前分支衍生创建一个分支
<div>
git从已有分支拉新分支开发
开发过程中经常用到从master分支copy一个开发分支,下面我们就用命令行完成这个操作:
1. 切换到被copy的分支(master),并且从远端拉取最新版本
$git checkout master
$git pull
2. 从当前分支拉copy开发分支
$git checkout -b dev
Switched to a new branch 'dev'
3. 把新建的分支push到远端
$git push origin dev
4. 拉取远端分支
$git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> dev
经过验证,当前的分支并没有和本地分支关联,根据提示进行下一步:
5. 关联
$git branch --set-upstream-to=origin/dev
6. 再次拉取 验证
$git pull
</div>