Git commit

The git commit command is used to save your changes to the local repository. This command takes the staged changes in your working directory and records them in the repository along with a descriptive message.



Tutorials dojo strip

Initial Example

To commit staged changes with a message, use:

git commit -m "Your commit message here"




COMMIT Options

OptionDescription
-a, --allStage all modified and deleted files before committing.
-m <msg>, --message <msg>Use the specified message as the commit message.
-F <file>, --file <file>Take the commit message from the specified file.
--author <author>Override the author for this commit.
--date <date>Override the date for this commit.
-e, --editEdit the commit message before committing.
--amendModify the last commit, including updating its message.
-C <commit>, --reuse-message <commit>Reuse the commit message from the specified commit.
-c <commit>, --reedit-message <commit>Reuse and edit the commit message from the specified commit.
--fixup <commit>Create a commit to fix up a previous commit.
--squash <commit>Create a commit to squash a previous commit.
--reset-authorUse the current user as the author for the commit.
--signoffAdd a Signed-off-by line at the end of the commit message.
-S, --gpg-sign[=<keyid>]GPG-sign the commit using the specified key.
--no-gpg-signDo not GPG-sign the commit, even if commit.gpgSign is set.
--template <file>Use the specified file as a template for the commit message.
-u <key-id>, --untracked=<key-id>Set the GPG key for signing commits if not already configured.
--cleanup <mode>How to strip spaces and comments from the message.
--statusInclude the status of staged files in the commit message template.
--no-statusDo not include the status of staged files in the commit message template.
-q, --quietSuppress commit summary message.
-v, --verboseShow unified diff between HEAD and the commit in the message template editor.
--[no-]verifyBypass the pre-commit and commit-msg hooks.
--allow-emptyCreate a commit, even if there are no changes staged.
--allow-empty-messageCreate a commit with an empty commit message.
--no-editUse the existing commit message without launching an editor.
--amendReplace the tip of the current branch by creating a new commit with the same parent as the current tip.
--no-post-rewriteBypass the post-rewrite hook.




Examples

1. Committing with a Message

To commit staged changes with a specific message:

git commit -m "Added new feature to the project"

This records your changes in the repository with the provided message.

2. Committing All Changes

To commit all changes (both staged and unstaged) in the working directory, use the -a option:

git commit -a -m "Fixed bugs and updated documentation"

This stages and commits all changes in tracked files.

3. Amending the Last Commit

To modify the most recent commit, including its message, use the --amend option:

git commit --amend -m "Updated commit message with more details"

This allows you to edit the previous commit, combining any staged changes with it.

4. Using an Editor to Write the Commit Message

To open your default text editor for writing a detailed commit message, simply use:

git commit

This will open your editor where you can type a multi-line commit message.

Scroll to Top