Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
当前回答
你可以给标签添加注释:
git tag -m 'this was a very good commit' tag1
按照惯例,您可以使用与分支名称相关的标记,或者您可以使用标记-f在主题分支的头部保留一个注释标记。
其他回答
Chris J建议的README可以工作,只要它使用.gitattribute中定义的自定义合并驱动程序进行设置。 这样,在合并期间始终保留README的本地版本。
分支的“描述”也被称为与元数据相关联的“注释”,它是不受支持的。
至少,对于一个README文件,你可以对任何分支执行:
$ git show myBranch:README
如果你的README在你的REPO的根目录,它将从任何路径工作,因为git show使用的路径是绝对的一个从REPO的顶部目录。
假设您想创建一个分支
git branch branch-20200328
git notes add branch-20200328 -m "This branch is for whatever"
git notes show branch-20200328
下面是一个git别名,它可以让你设置和读取当前分支的描述:
git config --global --add alias.about '!describe() { msg="$1"; git config branch."$(git rev-parse --abbrev-ref HEAD)".description ${msg:+"$msg"}; }; describe'
使用/例子:
(develop) $ git about
(develop) $ git about message
(develop) $ git about
message
(develop) $ git about "this is a new message"
(develop) $ git about
this is a new message
(develop) $ git checkout -b test_branch
Switched to a new branch 'test_branch'
(test_branch) $ git about
(test_branch) $ git about "this is the test branch"
(test_branch) $ git about
this is the test branch
(test_branch) $ git checkout -
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
(develop) $ git about
this is a new message
特别感谢@Felicio的回答,让我开始了。
这里有两个流行的建议:
git分支——edit-description:我们不喜欢这样,因为你不能推送它。也许我能记住我创建的分支是做什么的,但我的团队肯定不能。 README文件pr.分支。这是合并过程中的一个痛苦:非常容易合并冲突,当我们合并特性分支时,我们将从分支中拉入README。分支之间的差异也是一种痛苦。
我们决定创建一个孤儿分支——readme分支。孤儿分支是有自己独立历史的分支——你可能从Github的gh-pages分支知道它们。这个孤儿分支包含一个单独的README文件。它的内容包括:
master:
The default branch
mojolicious:
Start using Mojolicious
branch-whatever:
Description of the whatever branch
它是可推的和合并友好的。从任何分支查看README:
git show branches-readme:README
缺点是,当您想要更新README时,您需要签出奇怪的孤立分支,并且README不会随着分支的重命名、出现或消失而自动更新。不过,这对我们来说还好。
这样做:
git checkout --orphan branches-readme
# All the files from the old branch are marked for addition - skip that
git reset --hard
# There are no files yet - an empty branch
ls
vi README
# put in contents similar to above
git add README
git commit -m "Initial description of the branches we already have"
git push origin branches-readme
# get all your original files back
git checkout master
类似地,每个团队成员也可以创建他们自己的分支-$user孤儿分支,如果他们愿意,只要他们不把它们推给团队,就可以描述他们自己的私有分支。
通过进一步的工具,这也可以与git分支的输出集成。为了这个目的,可能需要一个自述书。可以考虑使用yaml文件来代替普通的README。
你可以给标签添加注释:
git tag -m 'this was a very good commit' tag1
按照惯例,您可以使用与分支名称相关的标记,或者您可以使用标记-f在主题分支的头部保留一个注释标记。