当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

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 :)

网友答案:

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.

网友答案:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: