自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Git使用規(guī)范流程

移動(dòng)開發(fā)
團(tuán)隊(duì)開發(fā)中,遵循一個(gè)合理、清晰的Git使用流程,是非常重要的。否則,每個(gè)人都提交一堆雜亂無章的commit,項(xiàng)目很快就會(huì)變得難以協(xié)調(diào)和維護(hù)。下面是ThoughtBot 的Git使用規(guī)范流程。我從中學(xué)到了很多,推薦你也這樣使用Git。

團(tuán)隊(duì)開發(fā)中,遵循一個(gè)合理、清晰的Git使用流程,是非常重要的。

否則,每個(gè)人都提交一堆雜亂無章的commit,項(xiàng)目很快就會(huì)變得難以協(xié)調(diào)和維護(hù)。

下面是ThoughtBot 的Git使用規(guī)范流程。我從中學(xué)到了很多,推薦你也這樣使用Git。

***步:新建分支

首先,每次開發(fā)新功能,都應(yīng)該新建一個(gè)單獨(dú)的分支(這方面可以參考《Git分支管理策略》)。

  1. # 獲取主干***代碼 
  2. $ git checkout master 
  3. $ git pull 
  4.  
  5. # 新建一個(gè)開發(fā)分支myfeature 
  6. $ git checkout -b myfeature 

第二步:提交分支commit

分支修改后,就可以提交commit了。

  1. $ git add --all 
  2. $ git status 
  3. $ git commit --verbose 

git add 命令的all參數(shù),表示保存所有變化(包括新建、修改和刪除)。從Git 2.0開始,all是 git add 的默認(rèn)參數(shù),所以也可以用 git add . 代替。

git status 命令,用來查看發(fā)生變動(dòng)的文件。

git commit 命令的verbose參數(shù),會(huì)列出 diff 的結(jié)果。

第三步:撰寫提交信息

提交commit時(shí),必須給出完整扼要的提交信息,下面是一個(gè)范本。

  1. Present-tense summary under 50 characters 
  2.  
  3. * More information about commit (under 72 characters). 
  4. * More information about commit (under 72 characters). 
  5.  
  6. http://project.management-system.com/ticket/123 

***行是不超過50個(gè)字的提要,然后空一行,羅列出改動(dòng)原因、主要變動(dòng)、以及需要注意的問題。***,提供對(duì)應(yīng)的網(wǎng)址(比如Bug ticket)。

第四步:與主干同步

分支的開發(fā)過程中,要經(jīng)常與主干保持同步。

  1. $ git fetch origin 
  2. $ git rebase origin/master 

第五步:合并commit

分支開發(fā)完成后,很可能有一堆commit,但是合并到主干的時(shí)候,往往希望只有一個(gè)(或最多兩三個(gè))commit,這樣不僅清晰,也容易管理。

那么,怎樣才能將多個(gè)commit合并呢?這就要用到 git rebase 命令。

  1. $ git rebase -i origin/master 

git rebase命令的i參數(shù)表示互動(dòng)(interactive),這時(shí)git會(huì)打開一個(gè)互動(dòng)界面,進(jìn)行下一步操作。

下面采用Tute Costa的例子,來解釋怎么合并commit。

  1. pick 07c5abd Introduce OpenPGP and teach basic usage 
  2. pick de9b1eb Fix PostChecker::Post#urls 
  3. pick 3e7ee36 Hey kids, stop all the highlighting 
  4. pick fa20af3 git interactive rebase, squash, amend 
  5.  
  6. # Rebase 8db7e8b..fa20af3 onto 8db7e8b 
  7. # Commands: 
  8. #  p, pick = use commit 
  9. #  r, reword = use commit, but edit the commit message 
  10. #  e, edit = use commit, but stop for amending 
  11. #  s, squash = use commit, but meld into previous commit 
  12. #  f, fixup = like "squash", but discard this commit's log message 
  13. #  x, exec = run command (the rest of the line) using shell 
  14. # These lines can be re-ordered; they are executed from top to bottom. 
  15. # If you remove a line here THAT COMMIT WILL BE LOST. 
  16. # However, if you remove everything, the rebase will be aborted. 
  17. # Note that empty commits are commented out 

上面的互動(dòng)界面,先列出當(dāng)前分支***的4個(gè)commit(越下面越新)。每個(gè)commit前面有一個(gè)操作命令,默認(rèn)是pick,表示該行commit被選中,要進(jìn)行rebase操作。

4個(gè)commit的下面是一大堆注釋,列出可以使用的命令。

  • pick:正常選中
  • reword:選中,并且修改提交信息;
  • edit:選中,rebase時(shí)會(huì)暫停,允許你修改這個(gè)commit(參考這里
  • squash:選中,會(huì)將當(dāng)前commit與上一個(gè)commit合并
  • fixup:與squash相同,但不會(huì)保存當(dāng)前commit的提交信息
  • exec:執(zhí)行其他shell命令

上面這6個(gè)命令當(dāng)中,squash和fixup可以用來合并commit。先把需要合并的commit前面的動(dòng)詞,改成squash(或者s)。

  1. pick 07c5abd Introduce OpenPGP and teach basic usage 
  2. s de9b1eb Fix PostChecker::Post#urls 
  3. s 3e7ee36 Hey kids, stop all the highlighting 
  4. pick fa20af3 git interactive rebase, squash, amend 

這樣一改,執(zhí)行后,當(dāng)前分支只會(huì)剩下兩個(gè)commit。第二行和第三行的commit,都會(huì)合并到***行的commit。提交信息會(huì)同時(shí)包含,這三個(gè)commit的提交信息。

  1. # This is a combination of 3 commits. 
  2. # The first commit's message is: 
  3. Introduce OpenPGP and teach basic usage 
  4.  
  5. # This is the 2nd commit message: 
  6. Fix PostChecker::Post#urls 
  7.  
  8. # This is the 3rd commit message: 
  9. Hey kids, stop all the highlighting 

如果將第三行的squash命令改成fixup命令。

  1. pick 07c5abd Introduce OpenPGP and teach basic usage 
  2. s de9b1eb Fix PostChecker::Post#urls 
  3. f 3e7ee36 Hey kids, stop all the highlighting 
  4. pick fa20af3 git interactive rebase, squash, amend 

運(yùn)行結(jié)果相同,還是會(huì)生成兩個(gè)commit,第二行和第三行的commit,都合并到***行的commit。但是,新的提交信息里面,第三行commit的提交信息,會(huì)被注釋掉。

  1. # This is a combination of 3 commits. 
  2. # The first commit's message is: 
  3. Introduce OpenPGP and teach basic usage 
  4.  
  5. # This is the 2nd commit message: 
  6. Fix PostChecker::Post#urls 
  7.  
  8. # This is the 3rd commit message: 
  9. # Hey kids, stop all the highlighting 

squash和fixup命令,還可以當(dāng)作命令行參數(shù)使用,自動(dòng)合并commit。

  1. $ git commit --fixup   
  2. $ git rebase -i --autosquash  

這個(gè)用法請(qǐng)參考這篇文章,這里就不解釋了。

第六步:推送到遠(yuǎn)程倉庫

合并commit后,就可以推送當(dāng)前分支到遠(yuǎn)程倉庫了。

  1. $ git push --force origin myfeature 

git push命令要加上force參數(shù),因?yàn)閞ebase以后,分支歷史改變了,跟遠(yuǎn)程分支不一定兼容,有可能要強(qiáng)行推送(參見這里)。

第七步:發(fā)出Pull Request

提交到遠(yuǎn)程倉庫以后,就可以發(fā)出 Pull Request 到master分支,然后請(qǐng)求別人進(jìn)行代碼review,確認(rèn)可以合并到master。

責(zé)任編輯:倪明 來源: 阮一峰的博客
相關(guān)推薦

2015-08-07 10:22:45

Git規(guī)范流程管理策略

2015-12-30 10:29:40

Git協(xié)作流程詳解

2021-02-26 07:35:57

Git版本工具

2020-08-14 08:00:39

Git數(shù)據(jù)層控制層

2021-09-13 06:43:36

UPS電源安裝

2020-05-12 14:57:06

git commit代碼前端

2023-09-04 13:55:44

分支masterhotfix

2021-08-09 06:57:41

CodeReview流程

2010-08-12 17:34:19

網(wǎng)站運(yùn)維流程規(guī)范

2022-08-15 14:31:58

數(shù)據(jù)開發(fā)

2015-10-20 11:22:34

iOS開發(fā)Git

2018-07-10 11:05:18

開發(fā)者技能命令

2023-02-08 09:16:19

Git操作工廠類

2018-07-10 10:45:00

規(guī)范Commit項(xiàng)目

2020-09-28 12:39:44

代碼規(guī)范管理

2009-06-23 09:25:01

谷歌人才流失

2017-02-08 13:33:34

AndroidJavaPhp

2009-08-25 10:27:29

IT管理流程企業(yè)內(nèi)控JP1

2019-12-06 11:14:57

Git開發(fā)系統(tǒng)

2009-12-31 13:33:35

Silverlight
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)