4

Git 小技巧 - 如何 Rebase 第一個 Commit?

 2 years ago
source link: https://blog.darkthread.net/blog/git-rebase-first-commit/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何 Rebase 第一個 Commit?-黑暗執行緒

Git 最大的好處是可以隨心所欲 Commit、切 Branch,想做就做,盡情開發,歷程再怎麼瑣碎噁心都無所謂,反正原始碼 Push 前都可用 Git Rebase 指令重新整理到美美的再公諸於世(延伸閱讀:Visual Studio Git Push 前置作業 - Squash),只要表現在外的一面永遠光鮮亮麗像個網美,誰管你在家摳腳挖鼻孔房間像垃圾堆?

不過有個小問題:git rebase -i commitId 的 commitId 是「整併範圍的前一個 Commit Id」,但如果我想連整併第一個 Commit 怎麼辦?例如:我想將黃框的四個 Commit 合併成一個,但第一個 Commit 726d6ea5 前面已經沒有 Commit 啊?哪來的 Commit Id?

Fig1_637899060841309121.png

今天學到一招 git rebase -i --root,以 --root 參數取代 commitId,我們就可以從第一個 Commit 開始 Rebase 囉。

Fig2_637899060842081149.png

將第二到四個 Commit 的命令由 pick 改為 squash (或簡寫 s):

Fig3_637899060842647511.png

這樣就能成功整併第一個 Commit 了! (灑花)

Fig4_637899060843144597.png

and has 0 comments

Comments

Be the first to post a comment

Post a comment

Comment
Name Captcha 27 + 23 =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK