Is there any way to incrementally build commit messages in git?

牧云@^-^@ 提交于 2019-12-13 11:38:01

问题


I'm wondering if it is possible to build git commit messages incrementally, documenting what I'm doing as I make code changes:

  1. Check out and begin work
  2. Enter commit message title (i.e. summary)
  3. Make a code change
  4. Update my commit message to describe change
  5. Repeat 3 and 4 until commit is ready

Is there any mechanism built into git to do this?


回答1:


git commit can take a commit message from a file using the -F option. So, you can do something like this:

# Do some work
$ echo 'Did some work' > commit-msg.txt
# Do some more work
$ echo 'Did some more work' >> commit-msg.txt
$ git commit -F commit-msg.txt



回答2:


You are supposed to do a commit for every small change you do that requires a message. This is especially easy with a distributed versioning system like git that you are using.

  1. Check out and begin work
  2. Make a code change
  3. Enter commit message and commit
  4. Repeat 2 and 3
  5. Push updates

And if you for some reason dislike this pattern and want to do the way you described, just use notepad and append to your message after coding a while and then copy paste it when commiting.




回答3:


If you really want to do it like this (I don't recommend you to do it that way though), then try this:

  1. Check out and begin work
  2. Make some code changes
  3. git commit
  4. Make some further code changes
  5. git commit --amend
  6. Repeat 4 & 5
  7. git commit --amend --reset-author to further reset the timestamp


来源:https://stackoverflow.com/questions/4799382/is-there-any-way-to-incrementally-build-commit-messages-in-git

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