红穆笔记

git apply

將補丁應用到文件和/或暫存區,但不創建提交。 另請參閱:`git am`

100% 瀏覽器本地處理 0 數據上傳

常用示例

顯示補丁文件的應用詳情

git apply {{[-v|--verbose]}} {{路徑/到/文件}}

應用補丁並將修改添加到暫存區

git apply --index {{路徑/到/文件}}

應用遠程補丁文件

curl {{[-L|--location]}} {{https://example.com/file.patch}} | git apply

應用遠程補丁文件

git apply --stat --apply {{路徑/到/文件}}

反向應用補丁(撤銷更改)

git apply {{[-R|--reverse]}} {{路徑/到/文件}}

將補丁結果存入暫存區但不修改工作區

git apply --cache {{路徑/到/文件}}

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Apply a patch to files and/or to the index without creating a commit. See also: `git am`. More information

Print messages about the patched files

git apply {{[-v|--verbose]}} {{path/to/file}}

Apply and add the patched files to the index

git apply --index {{path/to/file}}

Apply a remote patch file

curl {{[-L|--location]}} {{https://example.com/file.patch}} | git apply

Output diffstat for the input and apply the patch

git apply --stat --apply {{path/to/file}}

Apply the patch in reverse

git apply {{[-R|--reverse]}} {{path/to/file}}

Store the patch result in the index without modifying the working tree

git apply --cache {{path/to/file}}

命令信息

命令名git apply
用途將補丁應用到文件和/或暫存區,但不創建提交。 另請參閱:`git am`
適用平臺通用
示例數量6 條
官方文檔https://git-scm.com/docs/git-apply
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

git apply 命令是做什麼的?

將補丁應用到文件和/或暫存區,但不創建提交。 另請參閱:`git am`

git apply 怎麼用?

頁面按場景列出了6 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

git apply 最常用的操作是什麼?

顯示補丁文件的應用詳情:git apply {{[-v|--verbose]}} {{路徑/到/文件}}

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。