聊下git merge --squash


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

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

develop 主分支

1

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

git checkout -b develop_newfeature_ImportDataInterface origin/develop

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

2

現在我們需要將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。

3

1.txt文件是我們修改的文件,它現在待commit。現在我們只需要重新提交即可。

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

4

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

 

作者:王清培

出處:http://www.cnblogs.com/wangiqngpei557/

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM