将 git 提交与 Team Foundation 工作项相关联
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14933236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Associating git commits with Team Foundation work items
提问by Wilbert
Context
语境
A GitHub Enterprise installation used for development. Every developer has his own public repo, and the organization has the authorative repo. Pull requests are used for code reviews, and we loosely follow nvie's git flowbranching model.
用于开发的 GitHub Enterprise 安装。每个开发者都有自己的公共仓库,组织有权威的仓库。拉取请求用于代码,我们松散地遵循 nvie 的git flow分支模型。
A TFS installation used for issue tracking and deployment (the release branch). We mirror the release branch into a TFS repo.
用于问题跟踪和部署的 TFS 安装(发布分支)。我们将发布分支镜像到 TFS 存储库中。
Work Items
工作项目
Now the hard part is: How do we associate git commits (that may originally be done on the public branches of the developers) with TF work items?
现在困难的部分是:我们如何将 git 提交(最初可能在开发人员的公共分支上完成)与 TF 工作项相关联?
What I did
我做了什么
I've looked at the following projects for help:
我查看了以下项目以寻求帮助:
I've read references to associating commits with work item in both Git-TF projects, but I am unsure what tool to use, and how to go about it exactly.
我已经阅读了在两个 Git-TF 项目中将提交与工作项相关联的参考资料,但我不确定要使用什么工具,以及如何准确地使用它。
I would be fine if I had to run a script on the release branch commits to extract work item references from the commit message and associate them with changesets sent to TFS. However, a solution that allows the association in metadata (instead of commit messages) would be preferred.
如果我必须在发布分支提交上运行脚本以从提交消息中提取工作项引用并将它们与发送到 TFS 的变更集相关联,我会很好。但是,允许在元数据(而不是提交消息)中进行关联的解决方案将是首选。
What are my options to associate work items in TFS with git commits?
我有哪些选项可以将 TFS 中的工作项与 git 提交相关联?
采纳答案by Philippe
With git-tfs, you can associate workitems in a commit message using metadatas(and even force commit policy!).
使用git-tfs,您可以使用元数据(甚至强制提交策略!)在提交消息中关联工作项。
They are automaticaly associated when the commit are done in the TFS server ( if you use the rcheckin command)
当在 TFS 服务器中完成提交时,它们会自动关联(如果您使用rcheckin 命令)
And there is even a git-note created on the git commit to have the title of the workitem and a link toward the workitem!
甚至在 git commit 上创建了一个 git-note 来包含工作项的标题和指向工作项的链接!
But to use rcheckin in a synchronisation process between git and TFS, you should before (abolutely) understand how it works!
但是要在 git 和 TFS 之间的同步过程中使用 rcheckin,您应该(绝对)之前了解它是如何工作的!
When you rcheckin git commits in TFS, git-tfs, for each commit create the corresponding changeset in tfs and fetch the content of this changeset to recreate a git commit. So, even if it's (nearly) invisible for you in a normal worklow, you have the git commits after the rcheckin that are not the same than the original ones (there is a modification of the history!).
当您在 TFS 中检查 git commits 时,git-tfs,为每个提交在 tfs 中创建相应的变更集并获取此变更集的内容以重新创建一个 git 提交。因此,即使它在正常工作流中(几乎)对您来说是不可见的,您在 rcheckin 之后的 git 提交与原始提交不同(历史有修改!)。
That could be a big problem if this git reporitory is supposted to be the central repository because every commiters will have to do a rebase. Otherwise, it shouldn't be a problem because it's completly transparent, except in special cases but easily solvable.
如果这个 git 存储库被假定为中央存储库,那可能是一个大问题,因为每个提交者都必须进行 rebase。否则,它应该不是问题,因为它是完全透明的,除非在特殊情况下但很容易解决。
Not a perfect solution...
不是一个完美的解决方案...
回答by mcstar
If you use # in your git commit message as in git commit -m'fixes #123' TFS will automatically add the commit as a linked item in workitem specified.
如果您在 git commit 消息中使用 # ,如 git commit -m'fixes #123' TFS 将自动将提交添加为指定工作项中的链接项。
回答by VonC
Without having much information about those Git-TFS tools, note that you can add at any time metadata to a commit (withoutchanging the history / SHA1 of the repo) by adding notes.
在没有关于这些 Git-TFS 工具的太多信息的情况下,请注意,您可以通过添加注释随时将元数据添加到提交(无需更改存储库的历史记录/SHA1)。
See git notes
(or Git Tip of the Week: Git Notes).
请参阅git notes
(或本周 Git 提示:Git 笔记)。
By adding that information in a dedicated "note namespace", you can quickly store / retrieve an information like a Work Item reference from the note associated to a Git commit.
通过在专用的“注释命名空间”中添加该信息,您可以从与 Git 提交关联的注释中快速存储/检索诸如工作项引用之类的信息。
回答by regisbsb
You should be able to do it in the ms git tf:
你应该能够在 ms git tf 中做到这一点:
git tf checkin --associate=27631,27637
git tf checkin --associate=27631,27637
Help says:
帮助说:
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.