33

我正在做一些探索性的工作,我很可能会在同一任务的几个不同变体上花费 30 分钟。我想在 git 中跟踪它们,这样我就可以在方法之间来回跳转。如果有 3 或 6 或 9 个分支,我可能需要比分支名称更多的信息来区分它们。

将评论附加到新分支的最干净的方法是什么?

4

1 回答 1

60

You want branch descriptions:

git branch --edit-description

This will open up your editor and let you attach metadata to the branch. You can extract it with:

git config branch.<branch>.description

A couple of important notes:

  1. This is stored locally. By definition it can't be pushed since it's stored in .git/config. All the same it works great for this use case.

  2. If you delete the branch, the description will delete as well.

  3. You can push this description into merge commits if you set git config --global merge.branchdesc true. This means when you issue git merge --log <branch>, it'll force the branch description into the stock merge commit message. This has a lot of uses. For example, this is how I track topic branch release notes at my employer.

于 2012-08-09T14:54:48.760 回答