# git-am
> 原文: [https://git-scm.com/docs/git-am](https://git-scm.com/docs/git-am)
## 名稱
git-am - 從郵箱中應用一系列補丁
## 概要
```
git am [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
[--[no-]3way] [--interactive] [--committer-date-is-author-date]
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
[--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
[(<mbox> | <Maildir>)…?]
git am (--continue | --skip | --abort | --quit | --show-current-patch)
```
## 描述
將郵箱中的郵件拆分為提交日志消息,作者信息和修補程序,并將其應用于當前分支。
## OPTIONS
```
(<mbox>|<Maildir>)…?
```
要從中讀取修補程序的郵箱文件列表。如果您不提供此參數,則該命令將從標準輸入讀取。如果您提供目錄,它們將被視為Maildirs。
```
-s
```
```
--signoff
```
使用您自己的提交者標識在提交消息中添加`Signed-off-by:`行。有關詳細信息,請參閱 [git-commit [1]](https://git-scm.com/docs/git-commit) 中的簽收選項。
```
-k
```
```
--keep
```
將`-k`標志傳遞給 _git mailinfo_ (參見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) )。
```
--keep-non-patch
```
將`-b`標志傳遞給 _git mailinfo_ (參見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) )。
```
--[no-]keep-cr
```
使用`--keep-cr`,使用相同選項調用 _git mailsplit_ (參見 [git-mailsplit [1]](https://git-scm.com/docs/git-mailsplit) ),以防止它在行末端剝離CR。 `am.keepcr`配置變量可用于指定默認行為。 `--no-keep-cr`可用于覆蓋`am.keepcr`。
```
-c
```
```
--scissors
```
在剪刀線之前移除體內的所有物體(參見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) )。默認情況下可以使用`mailinfo.scissors`配置變量激活。
```
--no-scissors
```
忽略剪刀線(見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) )。
```
-m
```
```
--message-id
```
將`-m`標志傳遞給 _git mailinfo_ (參見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) ),以便將Message-ID標頭添加到提交消息中。 `am.messageid`配置變量可用于指定默認行為。
```
--no-message-id
```
不要將Message-ID標頭添加到提交消息中。 `no-message-id`用于覆蓋`am.messageid`。
```
-q
```
```
--quiet
```
安靜。僅打印錯誤消息。
```
-u
```
```
--utf8
```
將`-u`標志傳遞給 _git mailinfo_ (參見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) )。從電子郵件中獲取的建議提交日志消息被重新編碼為UTF-8編碼(配置變量`i18n.commitencoding`可用于指定項目的首選編碼,如果它不是UTF-8)。
這在git的早期版本中是可選的,但現在它是默認的。您可以使用`--no-utf8`覆蓋它。
```
--no-utf8
```
將`-n`標志傳遞給 _git mailinfo_ (參見 [git-mailinfo [1]](https://git-scm.com/docs/git-mailinfo) )。
```
-3
```
```
--3way
```
```
--no-3way
```
當補丁不能干凈地應用時,如果補丁記錄了它應該應用的blob的身份,則回退到三向合并,并且我們在本地可以使用這些blob。 `--no-3way`可用于覆蓋am.threeWay配置變量。有關更多信息,請參閱 [git-config [1]](https://git-scm.com/docs/git-config) 中的am.threeWay。
```
--ignore-space-change
```
```
--ignore-whitespace
```
```
--whitespace=<option>
```
```
-C<n>
```
```
-p<n>
```
```
--directory=<dir>
```
```
--exclude=<path>
```
```
--include=<path>
```
```
--reject
```
這些標志傳遞給應用補丁的 _git apply_ (參見 [git-apply [1]](https://git-scm.com/docs/git-apply) )程序。
```
--patch-format
```
默認情況下,該命令將嘗試自動檢測修補程序格式。此選項允許用戶繞過自動檢測并指定應將補丁解釋為的補丁格式。有效格式為mbox,mboxrd,stgit,stgit-series和hg。
```
-i
```
```
--interactive
```
以交互方式運行。
```
--committer-date-is-author-date
```
默認情況下,該命令將電子郵件中的日期記錄為提交作者日期,并使用提交創建時間作為提交者日期。這允許用戶使用與作者日期相同的值來說謊提交者日期。
```
--ignore-date
```
默認情況下,該命令將電子郵件中的日期記錄為提交作者日期,并使用提交創建時間作為提交者日期。這允許用戶使用與提交者日期相同的值來欺騙作者日期。
```
--skip
```
跳過當前的補丁。這僅在重新啟動已中止的修補程序時才有意義。
```
-S[<keyid>]
```
```
--gpg-sign[=<keyid>]
```
GPG簽名提交。 `keyid`參數是可選的,默認為提交者標識;如果指定,它必須粘在沒有空格的選項上。
```
--continue
```
```
-r
```
```
--resolved
```
在修補程序失敗(例如,嘗試應用沖突的修補程序)之后,用戶已手動應用它并且索引文件存儲應用程序的結果。使用從電子郵件和當前索引文件中提取的作者和提交日志進行提交,然后繼續。
```
--resolvemsg=<msg>
```
當發生補丁失敗時,< msg>將在退出前打印到屏幕上。這將覆蓋標準消息,通知您使用`--continue`或`--skip`來處理故障。這僅供 _git rebase_ 和 _git am_ 之間的內部使用。
```
--abort
```
恢復原始分支并中止修補操作。
```
--quit
```
中止修補操作但保持HEAD和索引不變。
```
--show-current-patch
```
顯示因“沖突”而停止“git am”時正在應用的補丁。
## 討論
提交作者姓名取自消息的“發件人:”行,提交作者日期取自消息的“日期:”行。在剝離公共前綴“[PATCH< anything>]”之后,“Subject:”行被用作提交的標題。 “Subject:”行應該在一行文本中簡明地描述提交的內容。
“From:”和“Subject:”行開始正文覆蓋從標題中獲取的相應提交作者姓名和標題值。
提交消息由從“主題:”獲取的標題,空白行和消息正文直到補丁開始的位置形成。每行末尾的多余空格會自動刪除。
該補丁預計將是內聯的,直接跟在消息之后。任何形式的行:
* 三個破折號和行尾,或
* 以“diff - ”開頭的行,或
* 一行以“索引:”開頭
被視為補丁的開頭,并且在第一次出現這樣的行之前終止提交日志消息。
最初調用`git am`時,為其指定要處理的郵箱的名稱。在看到第一個不適用的補丁時,它會在中間中止。您可以通過以下兩種方式之一從中恢復:
1. 通過使用`--skip`選項重新運行命令來跳過當前補丁。
2. 手解決工作目錄中的沖突,并更新索引文件,使其進入補丁應生成的狀態。然后使用`--continue`選項運行命令。
該命令在當前操作完成之前拒絕處理新郵箱,因此如果您決定從頭開始,請在運行帶有郵箱名稱的命令之前運行`git am --abort`。
在應用任何補丁之前,ORIG_HEAD設置為當前分支的尖端。如果您遇到多次提交有問題,例如在錯誤的分支上運行 _git am_ ,或者通過更改郵箱更容易修復提交中的錯誤(例如“From:”行中的錯誤),這很有用)。
## 掛鉤
該命令可以運行`applypatch-msg`,`pre-applypatch`和`post-applypatch`掛鉤。有關詳細信息,請參閱 [githooks [5]](https://git-scm.com/docs/githooks) 。
## 也可以看看
[git-apply [1]](https://git-scm.com/docs/git-apply) 。
## GIT
部分 [git [1]](https://git-scm.com/docs/git) 套件
- git
- git-config
- git-help
- git-init
- git-clone
- git-add
- git-status
- git-diff
- git-commit
- git-reset
- git-rm
- git-mv
- git-branch
- git-checkout
- git-merge
- git-mergetool
- git-log
- git-stash
- git-tag
- git-worktree
- git-fetch
- git-pull
- git-push
- git-remote
- git-submodule
- git-show
- git-log
- git-shortlog
- git-describe
- git-apply
- git-cherry-pick
- git-rebase
- git-revert
- git-bisect
- git-blame
- git-grep
- gitattributes
- giteveryday
- gitglossary
- githooks
- gitignore
- gitmodules
- gitrevisions
- gittutorial
- gitworkflows
- git-am
- git-format-patch
- git-send-email
- git-request-pull
- git-svn
- git-fast-import
- git-clean
- git-gc
- git-fsck
- git-reflog
- git-filter-branch
- git-instaweb
- git-archive
- git-bundle
- git-daemon
- git-update-server-info
- git-cat-file
- git-check-ignore
- git-checkout-index
- git-commit-tree
- git-count-objects
- git-diff-index
- git-for-each-ref
- git-hash-object
- git-ls-files
- git-merge-base
- git-read-tree
- git-rev-list
- git-rev-parse
- git-show-ref
- git-symbolic-ref
- git-update-index
- git-update-ref
- git-verify-pack
- git-write-tree