Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip the commit message step in "git commit --amend"? [duplicate]

I'm running a very rapid code-compile-test loop where I am amending changes to my commits far more often than not.

For example:

# Make some changes $ git commit -m "Added feature X" # Compile, test # Fix bugs $ git commit -a --amend 

I usually want the same commit message after I fix my bugs. Is there a way to make git skip firing up my EDITOR and just use the original commit message?

like image 680
nfm Avatar asked Mar 15 '11 04:03

nfm


People also ask

How do I ignore a commit message?

You can just add --no-edit to use the last message. This option existed since 2005 but only recently has been enabled for the --amend option. The other way is to add -C HEAD to the commit command with amend option.

How do I override a commit message in git?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.

How do I stop a commit amend?

If you delete the commit message (no need to delete the ones starting with # ) you will abort the git commit --amend command. You will get output like this: Aborting commit due to empty commit message.

How do I amend a commit before the last?

You can modify the most recent commit in the same branch by running git commit --amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit --amend to modify the most recent commit.


2 Answers

You can just add --no-edit to use the last message. This option existed since 2005 but only recently has been enabled for the --amend option.

The other way is to add -C HEAD to the commit command with amend option. This allows you to not just use the current commit's message but you can specify any other reference you like, so it's worth remembering it.

This is particularly useful when constructing a commit from various places in history and using one of those commit's messages. For example:

git checkout feature1^^ -- database/table1.sql git checkout feature1^^^^ -- logger.py git add -A && git commit -C feature1 

which would just use 2 commits from a feature1 and use the commit message from the last commit to feature1 - if that was a good description.

like image 145
Adam Dymitruk Avatar answered Sep 21 '22 16:09

Adam Dymitruk


You can also use

--reuse-message=<commit> Take an existing commit object, and reuse the log message and the authorship  information (including the timestamp) when creating the commit. 

Which allow you to use previous commit messages. This can also be part of a script or git alias.

like image 34
user2718704 Avatar answered Sep 25 '22 16:09

user2718704