问题
I am new in Git. Is there possible to create commit message step by step during developing? Because I find it very exhausted to review all changes during commit or committing to frequently. Sorry if I am crowding questions in here :)
回答1:
Just check changes in as you make them, don't wait until you have a large amount of changes. Not only will this make your commit messages more manageable, but it will help you version control your work better, allow you to track changes more narrowly, reverse them if need be etc etc.
回答2:
Nickstar's answer and ventsyv's answer are sound. Read them and take it in. However, if you really insist, you can prepare the message of the next commit in a text file before running git commit
.
- Create a file called
nextcommitmessage.txt
; keep it open in your favourite text editor, and prepare the message for your next commit in it, as you make changes in your working tree. - Stage everything that needs to go in the next commit (be careful not to stage
nextcommitmessage.txt
, though!). - Before committing, make sure you're happy with the contents of
nextcommitmessage.txt
. When you're ready to commit, run
git commit -F path/to/nextcommitmessage.txt
or, alternatively,
git commit --file=path/to/nextcommitmessage.txt
This will cause Git to use the contents of
nextcommitmessage.txt
as the message for this commit, instead of opening your core editor and prompting you to write a commit message from scratch.
Alternatively, you can start by making a series of small commits, and then squash them to just one commit (under the condition that you haven't pushed them). When you squash commits, Git will open your editor and invite you to combine the messages of the individual commits into one.
回答3:
The idea behind git is to commit soon and to commit often. So whenever you'd add to your commit message in your question, just commit instead with the partial message that you'd add to your big message. There is no need to push every single commit. That can and should be deferred until the point where you would commit in your current workflow.
来源:https://stackoverflow.com/questions/26360867/does-git-allow-me-to-write-my-next-commit-message-gradually-during-developing