在 Git 中合併檔案而不自動提交

John Wachira 2022年7月12日
在 Git 中合併檔案而不自動提交

本文將討論在 Git 中合併分支而不生成提交。在我們進入細節之前,讓我們看一些基本的 git merge 概念。

在 Git 中合併檔案而不自動提交

我們使用 git merge 命令在下面的上下文中合併分支。

如果要合併到 master 分支,請執行:

$ git merge <branch-name>

如果我們執行 git help merge 命令,我們將看到該命令的幫助頁面。幫助頁面顯示 git merge 命令預設呼叫提交。

我們可以通過 --commit 引數來合併和提交更改。

我們通過 --no-commit 標誌來合併並阻止 Git 建立提交。這樣,我們可以在提交合並結果之前進行編輯。

--ff 標誌將指示 Git 合併為快進合併,而 --no-ff 會建立提交,即使它是快進合併。

因此,要在不建立提交訊息的情況下合併,請執行:

$ git merge <branch-name> --no-commit --no-ff

Git 將執行合併但假裝它失敗並且不會生成提交。這是你在提交之前檢查和調整合並結果的機會。

請注意,這將限制你對索引檔案進行任何更改。在此狀態下,你無法刪除或新增檔案。

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

相關文章 - Git Merge