JackCA
JackCA

Reputation: 4885

Git - appending to an upcoming commit message

I'm looking for a way to achieve the following workflow:

  1. I make a small change to my code
  2. I append text describing the previous code change to a message that will be attached to my next commit
  3. Repeat steps 1 and 2 until ready to commit
  4. Commit with full message text automatically attached (possibly with an option to append a final text to the message)

EDIT: The message would only apply to a single commit. This would enable you to make continuous additions to your upcoming commit message.

Currently, the best solution is to commit on the first change, and then commit --amend on each following change and modify the previous message.

Upvotes: 0

Views: 2705

Answers (3)

Holger Just
Holger Just

Reputation: 55908

You can squash multiple small commits into a single one using an interactive rebase. See http://book.git-scm.com/4_interactive_rebasing.html for the description and an example.

Basically, you need to commit your changes one by one into single commits and then pack (or squash) them into a single one once you are finished. As this changes history, it should only be done in your local repository before the commits were pushed.

Upvotes: 2

Karl Bielefeldt
Karl Bielefeldt

Reputation: 49148

If you ever need to use git bisect to track down a bug, you will be glad for small commits.

On the other hand, if the changes really are trivial, like you're running through one per minute, an oft-overlooked solution is simply to keep a GUI window open and add lines to the commit message text area.

Upvotes: 2

Dean Harding
Dean Harding

Reputation: 72678

Why not change your "step 3" to simply "commit"? The best part of git is that it allows - even ecourages - many small, incremental commits to your local repository.

Upvotes: 4

Related Questions