婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Git的使用規范流程總結

Git的使用規范流程總結

熱門標簽:電銷機器人怎么收費 忻州外呼系統接口對接 嘟聲的電銷機器人 醫院地圖標注 湖北穩定外呼系統 地圖標注和圖片標注 洛陽便宜外呼系統廠家 語音平臺系統 滄州智能外呼系統收費

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

第一步:新建分支

首先,每次開發新功能,都應該新建一個單獨的分支。

# 獲取主干最新代碼
$ git checkout master
$ git pull
# 新建一個開發分支myfeature
$ git checkout -b myfeature

第二步:提交分支commit

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

$ git add --all
$ git status
$ git commit --verbose

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

git status 命令,用來查看發生變動的文件。

git commit 命令的verbose參數,會列出 diff 的結果。

第三步:撰寫提交信息

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

Present-tense summary under 50 characters

* More information about commit (under 72 characters).
* More information about commit (under 72 characters).

http://project.management-system.com/ticket/123
第一行是不超過50個字的提要,然后空一行,羅列出改動原因、主要變動、以及需要注意的問題。最后,提供對應的網址(比如Bug ticket)。

第四步:與主干同步

分支的開發過程中,要經常與主干保持同步。

$ git fetch origin
$ git rebase origin/master

第五步:合并commit

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

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

$ git rebase -i origin/master

git rebase命令的i參數表示互動(interactive),這時git會打開一個互動界面,進行下一步操作。

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

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個commit(越下面越新)。每個commit前面有一個操作命令,默認是pick,表示該行commit被選中,要進行rebase操作。

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

    pick:正常選中

    reword:選中,并且修改提交信息;

    edit:選中,rebase時會暫停,允許你修改這個commit(參考這里)

    squash:選中,會將當前commit與上一個commit合并

    fixup:與squash相同,但不會保存當前commit的提交信息

     exec:執行其他shell命令

上面這6個命令當中,squashfixup可以用來合并commit。先把需要合并的commit前面的動詞,改成squash(或者s)。

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

這樣一改,執行后,當前分支只會剩下兩個commit。第二行和第三行的commit,都會合并到第一行的commit。提交信息會同時包含,這三個commit的提交信息。

# 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

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

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

運行結果相同,還是會生成兩個commit,第二行和第三行的commit,都合并到第一行的commit。但是,新的提交信息里面,第三行commit的提交信息,會被注釋掉。

# 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

squashfixup命令,還可以當作命令行參數使用,自動合并commit。

$ git commit --fixup 
$ git rebase -i --autosquash

這個用法請參考這篇文章,這里就不解釋了。

第六步:推送到遠程倉庫

合并commit后,就可以推送當前分支到遠程倉庫了。

$ git push --force origin myfeature

git push命令要加上force參數,因為rebase以后,分支歷史改變了,跟遠程分支不一定兼容,有可能要強行推送(參見這里)。

第七步:發出Pull Request

提交到遠程倉庫以后,就可以發出 Pull Request master分支,然后請求別人進行代碼review,確認可以合并到master。

總結

以上就是這篇文章的全部內容,希望能對大家的學習或者工作帶來一定的幫助,如果有疑問大家可以留言交流。

您可能感興趣的文章:
  • git log根據特定條件查詢日志并統計修改的代碼行數
  • Python實現一個Git日志統計分析的小工具
  • 使用python分析git log日志示例
  • 總結PHP代碼規范、流程規范、git規范
  • git提交驗證規范并自動生成日志文件的方法

標簽:防城港 定州 宜賓 巴彥淖爾 96 日照 山南 內蒙古

巨人網絡通訊聲明:本文標題《Git的使用規范流程總結》,本文關鍵詞  Git,的,使用,規范,流程,總結,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Git的使用規范流程總結》相關的同類信息!
  • 本頁收集關于Git的使用規范流程總結的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 四会市| 天柱县| 周至县| 临沧市| 鄯善县| 怀来县| 万荣县| 晴隆县| 乌兰县| 山西省| 陆丰市| 肥乡县| 奎屯市| 合作市| 铜梁县| 昌乐县| 新巴尔虎左旗| 珠海市| 五台县| 凭祥市| 芮城县| 永平县| 岗巴县| 彭山县| 大冶市| 敖汉旗| 石林| 和林格尔县| 景谷| 宜宾市| 济宁市| 静乐县| 墨脱县| 彭州市| 肇源县| 社会| 延寿县| 达尔| 平顺县| 甘肃省| 澄江县|