天天看點

聊下git merge --squash

你經常會面臨着将dev分支或者很多零散的分支merge到一個公共release分支裡。

但是有一種情況是需要你處理的,就是在你的dev的分支裡有很多commit記錄。而這些commit是無需在release裡展現的。

develop 主分支

聊下git merge --squash

develop主分支最近的一個commit是”fix imageprint bug.”。我們拉出一個分支進行項目開發,裡面會有很多commit記錄。

git checkout -b develop_newfeature_ImportDataInterface origin/develop

develop_newfeature_ImportDataInterface 分支的commit log是和develop是一模一樣的。我們添加點修改commit。

聊下git merge --squash

現在我們需要将develop_newfeature_ImportDataInterface 分支的commit merge到develop主分支裡去。在合并進develop的時候我們希望在develop裡的commit log裡隻看見一次commit,而且這個commit的message不是很随意的,而是符合正規送出流程的約定格式的,比如,”develop:finished import data interface”。

我們就需要借助git merge –squash指令參數來重新準備送出。(這是一個明确的merge操作不同于git rebase,不要搞混淆這兩個指令的作用。)

git merge --squash develop_newfeature_ImportDataInterface

Updating cc1fea6..e6fb522

Fast-forward

Squash commit -- not updating HEAD

1.txt | 3 +++

1 file changed, 3 insertions(+)

--squash 會暫停commit送出。要不然一個merge會自動送出commit。

聊下git merge --squash

1.txt檔案是我們修改的檔案,它現在待commit。現在我們隻需要重新送出即可。

git commit -m'develop:finished import data interface'

聊下git merge --squash

這樣每次merge就會很清爽,一目了然,就算回頭reset也友善。

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面