红穆笔记

git commit

將文件提交到倉庫

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

常用示例

將暫存的文件提交到倉庫,附帶提交說明信息

git commit {{[-m|--message]}} "{{信息}}"

提交暫存的文件,並從指定文件中讀取附帶的提交信息

git commit {{[-F|--file]}} {{路徑/到/提交信息文件}}

自動暫存並提交所有修改過的和刪除的文件,附帶提交信息

git commit {{[-a|--all]}} {{[-m|--message]}} "{{信息}}"

提交暫存的文件,並使用指定的 GPG 密鑰簽名(若未指定參數則使用配置文件中的設定)

git commit {{[-S|--gpg-sign]}} {{密鑰id}} {{[-m|--message]}} "{{信息}}"

將當前暫存的更改追加到最近一次提交,並更新其哈希值

git commit --amend

只提交指定的(已暫存的)文件

git commit {{路徑/到/文件1 路徑/到/文件2 ...}}

即使沒有暫存文件也創建提交

git commit {{[-m|--message]}} "{{信息}}" --allow-empty

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

英文原文對照

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

Commit files to the repository. More information

Open an editor to write a message and commit staged files to the repository

git commit

Commit staged files to the repository with the specified message

git commit {{[-m|--message]}} "{{message}}"

Commit staged files with a message read from a file

git commit {{[-F|--file]}} {{path/to/commit_message_file}}

Auto stage all modified and deleted files and commit

git commit {{[-a|--all]}} {{[-m|--message]}} "{{message}}"

Commit staged files and sign them with the specified GPG key (or the one defined in the configuration file if no `key_id` is specified)

git commit {{[-S|--gpg-sign]}} {{key_id}} {{[-m|--message]}} "{{message}}"

Update the last commit by adding the currently staged changes, changing the commit's hash and open an editor to change the message

git commit --amend

Commit only specific (already staged) files

git commit {{path/to/file1 path/to/file2 ...}}

Create a commit with the specified message and description

git commit {{[-m|--message]}} "{{message}}" {{[-m|--message]}} "{{description}}"

命令信息

命令名git commit
用途將文件提交到倉庫
適用平臺通用
示例數量7 條
官方文檔https://git-scm.com/docs/git-commit
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

git commit 命令是做什麼的?

將文件提交到倉庫

git commit 怎麼用?

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

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

將暫存的文件提交到倉庫,附帶提交說明信息:git commit {{[-m|--message]}} "{{信息}}"

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

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