Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit only a message to GIT?

Tags:

git

Suppose that I have been working on a branch and have committed my work but want to add a message in the logs of what is next on the todo list for the branch. Times I might want to do this include:

  • Switching branches to work on something else - need to remind myself of what to do next
  • Weekend
  • Other

Is it possible to commit to git without committing any files? Anyother way to word this: Is it possible to commit only a message to GIT?

like image 910
sixtyfootersdude Avatar asked Sep 18 '13 17:09

sixtyfootersdude


People also ask

How do you supply a message to a commit?

The easiest way to create a Git commit with a message is to execute “git commit” with the “-m” option followed by your commit message. When using the Git CLI, note that you should restrict your commit message in order for it not to be wrapped.

How do I commit a single line in git?

For those who use Git Extensions: In the Commit window, select the file you want to partially commit, then select the text you want to commit in the right pane, then right-click on the selection and choose 'Stage selected lines' from the context menu.


2 Answers

Yes. It is possible. I can never remember how to do this and always need to Google (so I am writting a Q/A in hope that this will help me to remember).

The command is:

git commit --allow-empty --only 

The doc for --allow-empty reads:

Usually recording a commit that has the exact same tree as its sole parent commit is a mistake, and the command prevents you from making such a commit. This option bypasses the safety, and is primarily for use by foreign SCM interface scripts.

Doc makes sense but isn't easy to search for.

like image 90
sixtyfootersdude Avatar answered Sep 28 '22 13:09

sixtyfootersdude


You might also consider use an annotated tag instead. You could then remove the tag later without having to rewrite history. To me this makes more sense than adding empty commits to your history.

git tag -a TODO-feature-foo -m "next I'm going to..." git push origin :TODO-feature-foo 

Once no longer needed:

git push origin :TODO-feature-foo 
like image 38
John Ledbetter Avatar answered Sep 28 '22 12:09

John Ledbetter