luckyyyyy / blog

William Chan's Blog
https://williamchan.me/
175 stars 28 forks source link

正确的 git workflow #12

Open luckyyyyy opened 7 years ago

luckyyyyy commented 7 years ago

在工作中,经常会遇到很多使用git新手提交的commit,把git当成一个历史提交工具或者干脆当成编辑器的save功能,这是非常有问题的,我们可以来对比下下面两个记录。

 * fix typo
 * update eslint config
 * add chinese note in issue template
 * improve add missing html and svg tag 
 * Add types for vue-server-renderer (fix #5772) (#5775)
 * Merge pull request #167 from aaa/bbb
 * fix typo
 * update eslint config
 * add chinese note in issue template
 * Merge pull request #119 from aaa/bbb
 * Merge pull request #138 from aaa/bbb
 * update #1102
 * Merge branch 'aaa' into bbb
 * mprove add missing html and svg tag 

很明显,第一种是非常清爽的提交历史,但第二种,夹杂各种merge信息,非常混乱,那么如何正确的归档commit记录呢?

建立全新分支

在开始开发时,建立一个全新的分支用于开发feature。

git checkout -b dev_20170620_feature1

接下来我们进行开发,完成后的确认工作。

git status
git diff 
git add {modified files}
git commit -m "add feature1"

rebase

git rebase master

如果遇到冲突

git status
git add .
git rebase --continue