Does Git allow me to write my next commit message gradually during developing?

柔情痞子 提交于 2019-12-23 22:16:00

问题


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.

  1. 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.
  2. Stage everything that needs to go in the next commit (be careful not to stage nextcommitmessage.txt, though!).
  3. Before committing, make sure you're happy with the contents of nextcommitmessage.txt.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!