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:
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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With