Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit a commit message and nothing else?

Tags:

git

github

commit

When handling pull requests on GitHub, often I want to merge in commits from a branch with no changes. However, I would like to commit something just after the merge. I don't want to git commit --amend because that would change the commit I'm bringing in, so tracking the change gets more complicated.

Is there a way to git commit nothing but a message? The reason is because I might want to mention something in the Pull Request -- a URL pointing to a test case, or mention some other pull request so I can use a commit hook like Closes #123 in addition to the original pull request.

like image 954
Dead Pixel Avatar asked Sep 18 '12 13:09

Dead Pixel


People also ask

How do I commit an empty commit message?

How can I commit changes without specifying commit message? Why is it required by default? On Windows this command git commit -a --allow-empty-message -m '' makes commit with commit message " '' ", so it is better to use this command instead: git commit -a --allow-empty-message -m "" .

How do I change commit message only?

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 force an empty commit?

Git makes this process of pushing an empty commit super simple. It's like pushing a regular commit, except that you add the --allow-empty flag. You can see that the commit has been pushed to your branch without any changes after running the above commands.

Can you commit in git without providing a message?

Git commit messages are necessary to look back and see the changes made during a particular commit. If everyone will just commit without any message, no one would ever know what changes a developer has done.


2 Answers

To commit an empty commit, use git commit --allow-empty.

like image 166
user4815162342 Avatar answered Oct 24 '22 19:10

user4815162342


You can use git merge --no-commit branch to make the merge but not autocommit. You are now able to tweak the actual commit like if the merge failed, including changing the commit message.

Furthermore, you are able to enter a message by git merge -m "message" branch, which is added to the merge commit.

like image 40
Femaref Avatar answered Oct 24 '22 19:10

Femaref