git 合並commit提交


1、開發中 我們可能遇到這種情形: 在開發分支上多次commit

jari@DESKTOP-FBBQM3L MINGW64 /d/gitee/gitDemo (master)

$ git log

commit c8894255c8fbc436fe95daedbc035e412c92cca3 (HEAD -> master)

Author: tiankaixuan <17751676613@163.com>

Date:   Fri Dec 11 11:45:41 2020 +0800

   

    c 789

   

commit 9437f35e452e9a521aec9a253c5eff8e228155d1

Author: tiankaixuan <17751676613@163.com>

Date:   Fri Dec 11 11:45:20 2020 +0800

   

    b 456

   

commit 705f1fdf0236601c026188ceeb2796932fc75301

Author: tiankaixuan <17751676613@163.com>

Date:   Fri Dec 11 11:44:56 2020 +0800

   

    a 123

   

   

如果此時直接推送提交 , 小頭目就會懟你了,因為你的多次提交不便於對比代碼和查看提交內容,而且不好看。

   

   

2、rebase 粉墨登場

 git rebase -i  [startpoint]  [endpoint]

   

這個startpoint 和 endpoint 代表 開始的commitID 和 結束的commitID 。

   

該命令的就是對 startpoint 和 endpoint 之間所有的commitID進行操作。

   

(但是不包括 startpoint)

   

(如果只指定 startpoint , 那么endpoint默認指向當前節點)

   

   

3、執行

git rebase -i 705f1fdf0236601c026188ceeb2796932fc75301

   

   

pick:保留該commit(縮寫:p)

reword:保留該commit,但我需要修改該commit的注釋(縮寫:r)

edit:保留該commit, 但我要停下來修改該提交(不僅僅修改注釋)(縮寫:e)

squash:將該commit和前一個commit合並(縮寫:s)

fixup:將該commit和前一個commit合並,但我不要保留該提交的注釋信息(縮寫:f)

exec:執行shell命令(縮寫:x)

drop:我要丟棄該commit(縮寫:d)

   

我們需要的是合並 因此只需將 pick 改成 s ,然后保存退出。

   

   

   

4、保存退出后自動進入到新的交互頁面

   

可以看到上面還是存在 2次提交信息 , 所以直接刪除 , 添加新的提交信息

   

5、若是想合並 git rebase -i "commitID" 中的commitID

  • 那么可以直接使用 git rebase HEAD~3 ,那么此時合並的就是最近提交的3次分支

git rebase HEAD~3

   

6、保存退出。

使用 git log 查看日志


免責聲明!

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



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