XiWind 西風之劍
HomeTechProContactGitHub
  • About
  • Git
    • Windows Terminal、PowerShell 安裝
    • Git 開始使用
    • Branch 入門
    • 合併多個 Commit , 編輯
    • 額外功能
  • deep learning
    • Dilated Convolution
  • Python
    • GIL 【全域直譯器鎖】
    • PyPy 【JIT 編譯器】
    • Decorator 【修飾器】
      • Class Decorators
  • Python library
    • abc 【抽象 Class】
      • ABC, ABCMeta
      • __abstractmethods__, get_cache_token, update_abstractmethods
    • dataclasses 【數據 Class】
      • make_dataclass(), replace(), is_dataclass(), __post_init__
    • enum 【列舉 Class】
      • Flag, auto(), unique, verify()
      • 範例
    • concurrent.futures 【執行緒、程序】
      • Future, Module Functions
    • queue 【佇列、同步】
      • full(), empty(), qsize(), join(), task_done()
    • functools 【可調用物件】
      • ordering、wrapper、partial
      • Overloading
    • heapq 【堆積佇列】
      • heapify(), merge(), nlargest(), nsmallest()
    • time 【時間】
      • time(), monotonic(), perf_counter()...
      • sleep(), 範例...
    • logging 【日誌】
Powered by GitBook
On this page
  • Commit Merge 模式
  • Interactive rebase
  • 製作 Remote repository 副本
  • 參考資料

Was this helpful?

  1. Git

合併多個 Commit , 編輯

我們深入探討每位開發人員都應該掌握的基本 Git 技巧。包括:合併多個提交、編輯提交和 Interactive rebase 等。逐步了解如何優化您的 Git 工作流程,有效地結合多個提交、精煉提交消息以及利用 Interactive rebase 的強大功能。

PreviousBranch 入門Next額外功能

Last updated 1 year ago

Was this helpful?

Commit Merge 模式


  • Merge commit: 保留 Branch commit 歷程,又稱為 no fast-forward merge。(預設的 Merge 模式)

  • Squash merge: 忽略並壓縮 Branch commit 歷程。

  • Rebase merge (基底合併): 將 Branch commit 歷程加入到 Main branch commit,又稱為 fast-forward merge 。(從 Branch 取得最新內容,並重新定位 Commit 基準)

  • Cherry-Pick (揀選): 從一個 Branch 中獲取單個 Commit 並將其 Merge 於另一個 Branch。

將 Merge commit (Branch merge) 到當前 Branch。

SHELL
git merge <要合併的 Branch>

執行 Rebase merge 到當前 Branch。。

SHELL
git rebase <Branch 名稱>

當有多位開發者時,經常將 Remote main branch 合併到本地功能性 Branch,能盡早發現衝突。

執行 Cherry-pick 到當前 Branch。。

SHELL
git cherry-pick <Git SHA-1 ID>

同一 Repository 的 Git SHA-1 ID 不會重複。

Interactive rebase


Interactive rebase 允許以互動的方式(interactive)修改、刪除、合併和拆分同一 Branch 的 Commit。

Interactive rebase 是一個強大的工具,但應該小心使用它,因為它可以改變 Branch 的歷史,這可能會給在同一 Branch 上工作的其他開發人員帶來問題。通常建議只在本地 Branch 或尚未 Push branch 上使用 Interactive rebase。

  1. 執行 Interactive rebase ,顯示編輯介面。 (使用預設編輯器開啟)

SHELL
git rebase -i HEAD~7
git rebase -i HEAD~<顯示 Commit 數量>

git log 由新到舊(上到下)顯示;git rebase -i 由舊到新(上到下)顯示,並且不會顯示 Commit 日期。

Interactive rebase 編輯說明

<Commands> <Git SHA-1 ID> <Commit 摘要> , 常用的 <Commands>:

pick: Commit 維持不變

squash: 將此條 Commit 併入前一條 Commit。

drop: 刪除 Commit。

reword: 編輯 Commit。

label: 使用標籤標記 Commit。

跳過 Conflict commit。

SHELL
git rebase --skip

繼續因Conflict 而暫停的 Interactive rebase。

SHELL
git rebase --continue

製作 Remote repository 副本


  1. 建立空白的 Remote repository 副本。

可以 clone URL 或 建立空白副本。

  1. Push 所有 Tags、本地 Branchs。

SHELL
git push --mirror <Github網址>.git

此命令會對 Remote repository 產生重大影響,因為它會更新或創建 Branchs 和 tags。因此,應謹慎使用並且擁有的必要權限。

參考資料


Windows 上的 Git:如何設置合併工具? - 堆棧溢出
git - merge --squash 和 rebase 有什麼區別? - 堆棧溢出
Git Rebase VS Merge VS Squash:如何選擇合適的? - 開發社區
合併策略和壓縮合併 - Azure Repos | Microsoft Learn
About pull request merges - GitHub Docs
Git fast-forward VS no fast-forward merge - Stack Overflow
Merge commit
Squash merge
Rebase commit
Cherry-Pick
編輯介面
使用 squash 後,壓縮的訊息
使用 squash 後,log 訊息
導入 Repository
建立空白 Repository
Page cover image