将Git提交与Team Foundation工作项关联

24

背景

一个用于开发的 GitHub Enterprise 安装。每个开发人员都有自己的公共存储库,组织拥有权威存储库。我们使用拉取请求进行代码审查,并松散地遵循 nvie 的 git flow 分支模型。

一个用于问题跟踪和部署(发布分支)的 TFS 安装。我们将发布分支镜像到一个 TFS 存储库中。

工作项

现在困难的部分是:我们如何将可能最初在开发人员的公共分支上完成的 git 提交与 TF 工作项关联起来?

我的做法

我查看了以下项目以寻求帮助:

我已经阅读了关于在Git-TF项目中将提交与工作项相关联的参考资料,但我不确定要使用什么工具以及如何确切地进行操作。
如果必须在发布分支提交上运行脚本以从提交消息中提取工作项引用并将其与发送到TFS的变更集相关联,则我会很满意。然而,最好是一种允许在元数据中进行关联(而不是提交消息)的解决方案。
我的选项有哪些可以将TFS中的工作项与git提交相关联?
4个回答

26
如果您在git提交消息中使用#,例如git commit -m'fixes#123',TFS将自动将提交作为链接项添加到指定的工作项中。

2
是的,这个功能是在最新版本中引入的,它会导致无尽的问题,因为我们有成千上万的提交是由已接受的拉取请求产生的,这些请求的标题中包含“合并拉取请求#142”。显然这指的是GH:E拉取请求编号而不是tfs问题。 - Wilbert
5
@Wilbert 有一种方法可以避免这种情况:合并拉取请求文档 - Philippe
这个使用 git-tfs 桥接器吗?还是在最新的 TFS/VSTS 中支持? - ryanwebjackson

19
使用 git-tfs,您可以使用 元数据 在提交信息中关联工作项(甚至可以强制执行提交策略!)。

当在 TFS 服务器上完成提交(如果使用 rcheckin 命令 )时,它们会自动关联。

甚至会在 git 提交上创建一个 git-note,包含工作项的标题和指向工作项的链接!

但是,在 git 和 TFS 之间同步过程中使用 rcheckin,您必须(绝对)先了解其工作原理!

当您将 git 提交 rcheckin 到 TFS 中时,git-tfs 会为每个提交在 tfs 中创建相应的变更集,并获取该变更集的内容以重新创建 git 提交。因此,即使在正常工作流程中几乎看不到,在 rcheckin 之后有与原始提交不同的 git 提交(历史记录有所修改!)。

如果此 git 存储库被假定为中央存储库,则可能会出现大问题,因为每个提交者都必须进行变基。否则,它不应该是一个问题,因为它完全透明,除了特殊情况但很容易解决。

这不是一个完美的解决方案...


1
有趣。比我的答案更精确。+1 - VonC
Git TFS虽然功能更全面且速度更快,但非常脆弱;而MS Git TF虽然功能有限,但非常稳定可靠。 - regisbsb
@regisbsb 错了!我非常确定 git-tfs 在 git-tf 所做的事情上是一样可靠的。唯一的区别是 git-tfs 正在尝试支持分支,而 git-tf 甚至没有考虑过,因为 TFVC 分支支持是最糟糕的混乱,你甚至无法想象。每次我支持一个边缘案例,就会有另一个更傻的要支持!如果你想像我一样可靠,只需使用“--ignore-branches”选项。就这样! - Philippe
只下载单个分支在我的大多数TFS仓库中失败,除非是正统的分支。Git-tf是无缺陷的。它只需获取tfs路径到git并完成。虽然我相信你的项目很有前途,但你应该看一下ms one的java源代码。 - regisbsb

6
没有太多关于那些Git-TFS工具的信息,但需要注意的是您可以通过添加注释来随时向提交添加元数据(无需更改存储库的历史记录/ SHA1)。请参见git notes(或Git本周提示:Git笔记)。通过在专用的“注释名称空间”中添加信息,您可以快速地存储/检索像工作项引用之类的信息,这些信息与Git提交相关联。

谢谢,我知道git notes,我认为nodirt Git-TF项目使用它们。然而,那只是答案的一部分。 - Wilbert

3

您应该可以在ms git tf中完成它:

git tf checkin --associate=27631,27637

帮助文档如下:

usage: git-tf checkin [--help] [--quiet|-q|--verbose] [--message|-m=<msg>] [--metadata|--no-metadata] [--renamemode=<all|justFiles|none>] [--deep|--shallow] [--squash=<commit id>|--autosquash]
[--resolve=<workitem id>] [--associate=<workitem id>] [--mentions] [--no-lock] [--preview|-p] [--bypass|--gated|-g=<definition>] [--keep-author|--ignore-author] [--user-map=[<file path>]]

Arguments:
    --help                Displays usage information
    --quiet, -q, --verbose
                          Determines the output detail level
    --message, -m=<msg>   Use the given <msg> as the changeset comment
    --metadata, --no-metadata
                          Determine whether to include git commit meta data in the changeset comment when checking in deep. If omitted, value provided during configure is used.
    --renamemode=<all|justFiles|none>
                          The rename mode to use when pending changes. Specify either "all", "justFiles" or "none" (default: justFiles)
    --deep, --shallow Creates a "deep" check-in, checking in a TFS changeset for each git commit since the latest TFS changeset(requires linear history or "--squash" or "--autosquash"), or
                          "shallow", checking in a single changeset for all commits.If omitted, the depth value provided during clone or configure is used.
    --squash=< commit id>, --autosquash
                          Specifies how check in should operate in the deep mode if one commit has more than one parent
    --resolve=< workitem id>
                          ID of the TFS work item to resolve during check-in
    --associate=< workitem id>
                          ID of the TFS work item to associate during check-in
    --mentions Add references in the commit comments for any work items linked to the corresponding changeset.
    --no-lock             Does not take a lock on the server path before committing (dangerous)
    --preview, -p Displays a preview of the commits that will be checked in TFS
    --bypass, --gated, -g=<definition>
                          Bypass gated check-in or specify a gated build<definition> to use
    --keep-author Use the commit author as the changeset owner when checking in deep.The commit author should be known to TFS either by his name or e-mail address.To use this option you should
                 be either a TFS project administrator or have the "Check in other users' changes" permission.
    --ignore-author Use the current authenticated user as the changeset owner.
    --user-map=[< file path >]
                          Specifies an absolute or relative path to a file providing mapping between Git repository commit authors and TFS user identities. (default: ./USERMAP) To generate a template
                          mapping file, run the checkin command in preview mode with the --keep-author and --deep options specified.

Creates a check-in of the changes in the current master branch head, provided it is parented off a commit converted from a TFS changeset.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接