Julian
Julian

Reputation: 452

Git commit messages if I split a single task into 2 commits

For example, if I haven’t finished a task at the end of a day but want to commit and push my work. The next day I’ll finish the task and commit the finished task again. What should the 2 commit messages look like?

For example Apply new Changes (Part1) and Apply new Changes (Part2) looks not like a good commit message to me.

Upvotes: 0

Views: 1344

Answers (2)

Melebius
Melebius

Reputation: 6695

Unfinished work should not be pushed. A commit should be atomic1, containing one (and only one) complete task unless it can be split into reasonable subtasks.

If you want to push your unfinished work for the backup purpose, use a branch that is OK to rebase the next day when you amend your previous commit.


1 Atomic in the meaning of using VCS, there is another meaning describing how VCS shall work internally.

Upvotes: 1

ElpieKay
ElpieKay

Reputation: 30888

Better not push such commits to the target branch. You could commit as often as possible with whatever commit messages you like. Consider them as drafts. You will have little chance to lose your changes. Every commit stays long enough. You could push them to a backup branch or a backup repository in another host if you don't think the local repository is safe enough. When you finish one task, squash all the related draft commits into one, with git reset --soft && git commit, git rebase -i, or git merge --squash. Write the message carefully to include helpful and well-formatted infomation for this formal commit.

Upvotes: 3

Related Questions