Linux command
git-commit 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Commit staged changes
git commit -m "[message]"
Commit all tracked changes
git commit -am "[message]"
Amend last commit
git commit --amend
Commit with editor
git commit
Empty commit
git commit --allow-empty -m "[message]"
Commit with signoff
git commit -s -m "[message]"
Fixup commit
git commit --fixup [commit]
Squash commit
git commit --squash [commit]
说明
git commit records changes to the repository by creating a new commit object containing the currently staged changes, metadata, and a descriptive message. Each commit represents a snapshot in the repository's history, identified by a unique SHA-1 hash and linked to its parent commit(s). The standard workflow involves staging changes with git add, then committing those staged changes. The -a flag shortcuts this by automatically staging all modified tracked files before committing. Commit messages can be provided inline with -m or by opening an editor where you can write multi-line messages with detailed explanations. The --amend option modifies the most recent commit instead of creating a new one, useful for correcting mistakes or adding forgotten changes. This rewrites history, so amended commits should not be pushed to shared branches unless force-pushing is acceptable. Advanced options support signing commits with GPG (--gpg-sign), adding metadata like co-authors or issue references, and creating specialized commits for rebase workflows. The --fixup and --squash options create commits meant to be combined with earlier commits during interactive rebasing, supporting cleanup of messy development history. Empty commits (--allow-empty) are occasionally useful for triggering CI/CD pipelines or marking milestones without actual code changes. The --verbose flag shows the full diff in the editor, helping write accurate commit messages by reviewing what's being committed.
参数
- -m, --message _msg_
- Commit message.
- -a, --all
- Stage all modified files.
- --amend
- Amend previous commit.
- --no-edit
- Use previous message.
- -s, --signoff
- Add Signed-off-by.
- --allow-empty
- Allow empty commits.
- --fixup _commit_
- Fixup for commit.
- --squash _commit_
- Squash into commit.
- -v, --verbose
- Show diff in editor.
- --author _author_
- Override author.
- --date _date_
- Override the author date.
- -C, --reuse-message _commit_
- Reuse the message (and authorship) from an existing commit.
- -c, --reedit-message _commit_
- Like --reuse-message but open the editor to edit the message.
- -F, --file _file_
- Take the commit message from _file_.
- -S, --gpg-sign _keyid_
- GPG-sign the commit.
- -n, --no-verify
- Skip the pre-commit and commit-msg hooks.
- -e, --edit
- Force opening the editor (with -m/-F).
- -p, --patch
- Interactively choose hunks to stage and commit.
- --dry-run
- Show what would be committed without creating a commit.
FAQ
What is the git-commit command used for?
git commit records changes to the repository by creating a new commit object containing the currently staged changes, metadata, and a descriptive message. Each commit represents a snapshot in the repository's history, identified by a unique SHA-1 hash and linked to its parent commit(s). The standard workflow involves staging changes with git add, then committing those staged changes. The -a flag shortcuts this by automatically staging all modified tracked files before committing. Commit messages can be provided inline with -m or by opening an editor where you can write multi-line messages with detailed explanations. The --amend option modifies the most recent commit instead of creating a new one, useful for correcting mistakes or adding forgotten changes. This rewrites history, so amended commits should not be pushed to shared branches unless force-pushing is acceptable. Advanced options support signing commits with GPG (--gpg-sign), adding metadata like co-authors or issue references, and creating specialized commits for rebase workflows. The --fixup and --squash options create commits meant to be combined with earlier commits during interactive rebasing, supporting cleanup of messy development history. Empty commits (--allow-empty) are occasionally useful for triggering CI/CD pipelines or marking milestones without actual code changes. The --verbose flag shows the full diff in the editor, helping write accurate commit messages by reviewing what's being committed.
How do I run a basic git-commit example?
Run `git commit -m "[message]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -m, --message _msg_ do in git-commit?
Commit message.