跳过主要内容
通过 Git 提及,您可以将存储库的历史记录和更改直接带入与 Cline 的对话中。您可以使用 @git-changes 引用未提交的更改,或使用 @[commit-hash] 引用特定的提交。 当您在聊天中输入 @ 时,您可以从菜单中选择“Git 更改”或直接输入 @git-changes。对于特定提交,输入 @ 后跟提交哈希(至少 7 个字符)。Cline 将立即看到 git 状态、差异、提交消息和其他相关信息。 当我试图理解代码更改或排查最近提交引入的问题时,我经常使用 git 提及。与其尝试复制粘贴差异或提交日志,不如直接问:
I think this commit broke our authentication flow: @a1b2c3d

Can you explain what changed and why it might be causing the issue?
这会为 Cline 提供完整的提交信息,包括提交消息、作者、日期和完整的差异。然后,Cline 可以分析具体更改了什么以及它可能如何影响代码库的其他部分。 当您正在进行更改并希望在提交前获得反馈时,@git-changes 提及非常完美:
Here are my current changes: @git-changes

I'm trying to implement a new feature for user profiles. Does my approach make sense?
Are there any potential issues or improvements you'd suggest?
这会向 Cline 显示您所有未提交的更改,包括新文件、修改的文件及其差异。然后,Cline 可以审查您的更改并提供有关您实现的反馈。 Git 提及与文件提及结合使用时尤其强大。当我调查一个错误时,我通常会同时引用两者:
I think this commit introduced a bug: @a1b2c3d

Here's the current implementation: @/src/components/Auth.jsx

How can I fix the issue while preserving the intended functionality?
下次您处理代码更改或调查问题时,尝试使用 git 提及而不是手动描述或复制更改。您将获得更准确的帮助,因为 Cline 可以准确地看到更改了什么以及在什么上下文中进行了更改。

幕后工作原理

当您在消息中使用 git 提及时,幕后会发生什么

针对 Git 更改 (@git-changes)

  1. 当您发送消息时,Cline 会检测文本中的 @git-changes 模式
  2. 扩展程序运行 git 命令以获取存储库的当前工作状态
  3. 它捕获 git statusgit diff 的输出以查看所有未提交的更改
  4. 此信息以结构化格式附加到您的消息中
    <git_working_state>
    On branch main
    Changes not staged for commit:
      modified: src/components/Button.jsx
      modified: src/styles/main.css
    
    [Complete diff output with all changes]
    </git_working_state>
    

针对特定提交 (@[commit-hash])

  1. 当您发送消息时,Cline 会检测 @ 后跟提交哈希的模式
  2. 扩展程序运行 git show 和相关命令以获取有关该提交的信息
  3. 它检索提交消息、作者、日期和完整的差异
  4. 此信息以结构化格式附加到您的消息中
    <git_commit hash="a1b2c3d">
    commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t
    Author: Developer Name <[email protected]>
    Date: Mon May 20 14:30:45 2025 -0700
    
    Fix authentication bug in login form
    
    [Complete diff output showing all changes in the commit]
    </git_commit>
    
每当您使用 git 提及时,此过程都会自动发生,使 AI 能够完全了解您的代码更改,而无需您复制粘贴差异或提交日志。