yxfanxiao / yxfanxiao.github.io

My Blog Space
3 stars 0 forks source link

Git #13

Open yxfanxiao opened 8 years ago

yxfanxiao commented 8 years ago

Git使用交流

Git是一个分布式版本控制系统。

下载安装

Download Git for Windows

会同时安装Git和Git Bash。Git Bash是Windows下的命令行工具,可以使用linux下的一些命令。

配置用户名

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

基础用法

克隆

$ git clone <版本库的网址> <本地目录名>

If you get the error message unable to get local issuer certificate, try the following workaround

$ git config --global http.sslVerify false

提交修改

分为2步

$ git add <文件>
$ git commit -m <信息>  

查看当前状态

$ git status

查看提交历史

$ git log

撤销

回退至某个版本(完全撤销工作区和暂存区的更改)

$ git reset --hard <commit hash>

单个文件撤销至head版本(撤销工作区的更改)

$ git checkout -- <file>

推送

$ git push orgin <分支名>

分支

查看分支

$ git branch

创建分支

$ git checkout -b <分支>

选择分支

$ git checkout <分支>

fetch分支

从远程获取最新的版本,不自动合并。

合并分支

$ git merge --no-ff dev

--no-ff = none fast-forword,会生成单独的合并节点。

git pull

自动合并。

git pull = git fetch + git merge

更好的合并方式,合并前可以先看一下情况。

$ git fetch origin master:tmp
$ git diff tmp
$ git merge tmp

打标签

$ git tag -a <标签名> -m <信息>
$ git push origin <标签名>

Git 工作流

master分支与产品的发布一致(线上代码)。

dev分支用来合并大家的功能分支(,测试后),合并至master分支。

每开发一个功能,在本地新建一个_feature-[name]_分支,开发完成后,合并至dev。

有issue需要解决时,在本地新建一个_issue-[id]_分支,开发完成后,合并至dev。

小练习

  1. 在Github上建立一个仓库,clone至本地。
  2. 在本地新建一个feature-initial分支。
  3. 新建一个文件,commit。(status -> add -> commit)
  4. 查看一下提交记录(git log)。
  5. 回到master分支,合并feature分支。
  6. 推送master分支至Github origin。
  7. 删除feature分支。
yxfanxiao commented 7 years ago
$ git rebase -i <commit>
yxfanxiao commented 7 years ago
$ git cherry-pick <commit>