Git的使用规范流程总结
下面是ThoughtBot 的Git使用规范流程。我从中学到了很多,推荐你也这样使用Git。 第一步:新建分支 首先,每次开发新功能,都应该新建一个单独的分支。 # 获取主干最新代码 $ git checkout master $ git pull # 新建一个开发分支myfeature $ git checkout -b myfeature 第二步:提交分支commit 分支修改后,就可以提交 $ git add --all $ git status $ git commit --verbose
第三步:撰写提交信息 提交 Present-tense summary under 50 characters * More information about commit (under 72 characters). http://project.management-system.com/ticket/123 第四步:与主干同步 分支的开发过程中,要经常与主干保持同步。 $ git fetch origin $ git rebase origin/master 第五步:合并commit 分支开发完成后,很可能有一堆 那么,怎样才能将多个 $ git rebase -i origin/master
下面采用Tute Costa的例子,来解释怎么合并 pick 07c5abd Introduce OpenPGP and teach basic usage pick de9b1eb Fix PostChecker::Post#urls pick 3e7ee36 Hey kids,stop all the highlighting pick fa20af3 git interactive rebase,squash,amend # Rebase 8db7e8b..fa20af3 onto 8db7e8b # # Commands: # p,pick = use commit # r,reword = use commit,but edit the commit message # e,edit = use commit,but stop for amending # s,squash = use commit,but meld into previous commit # f,fixup = like "squash",but discard this commit's log message # x,exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However,if you remove everything,the rebase will be aborted. # # Note that empty commits are commented out 上面的互动界面,先列出当前分支最新的4个 4个 pick:正常选中 reword:选中,并且修改提交信息; edit:选中,rebase时会暂停,允许你修改这个commit(参考这里) squash:选中,会将当前commit与上一个commit合并 fixup:与squash相同,但不会保存当前commit的提交信息 exec:执行其他shell命令 上面这6个命令当中, pick 07c5abd Introduce OpenPGP and teach basic usage s de9b1eb Fix PostChecker::Post#urls s 3e7ee36 Hey kids,amend 这样一改,执行后,当前分支只会剩下两个 # This is a combination of 3 commits. # The first commit's message is: Introduce OpenPGP and teach basic usage # This is the 2nd commit message: Fix PostChecker::Post#urls # This is the 3rd commit message: Hey kids,stop all the highlighting 如果将第三行的 pick 07c5abd Introduce OpenPGP and teach basic usage s de9b1eb Fix PostChecker::Post#urls f 3e7ee36 Hey kids,amend 运行结果相同,还是会生成两个 # This is a combination of 3 commits. # The first commit's message is: Introduce OpenPGP and teach basic usage # This is the 2nd commit message: Fix PostChecker::Post#urls # This is the 3rd commit message: # Hey kids,stop all the highlighting
$ git commit --fixup $ git rebase -i --autosquash 这个用法请参考这篇文章,这里就不解释了。 第六步:推送到远程仓库 合并 $ git push --force origin myfeature
第七步:发出Pull Request 提交到远程仓库以后,就可以发出 总结 以上就是这篇文章的全部内容,希望能对大家的学习或者工作带来一定的帮助,如果有疑问大家可以留言交流。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |