先说结论:这行署名不是你仓库里的 hook 或模板加的,是 Cursor 自己塞的。关掉开关只能管住以后,已经提交的那些得重写历史才能去掉。下面是我自己踩完坑后的完整做法,命令都跑通了。
那天我在自己的项目里连着提交了十几次,回头翻
git log
想确认改了啥,结果发现每条 message 屁股后面都挂着一行:
Co-authored-by: Cursor <cursoragent@cursor.com> |
我没写过这行,也没人帮我提交。更烦的是 code review 的时候,队友会盯着问「Cursor 是谁,怎么老在改我的文件」。我决定把它弄干净。
我第一反应是某个 git hook 或者提交模板干的。所以先排查,三条命令就够:
# 1) 有没有自定义 hook(.sample 是样例,忽略) ls -la .git/hooks/ | grep -v '.sample' # 2) 有没有提交模板 git config --get commit.template # 3) 有没有改过 hooks 路径 git config --get core.hooksPath |
我这三条全是空的。也就是说,仓库本身是干净的——这行根本不来自我的项目,而是 Cursor 在提交时用
--trailer
(老版本是
--footer
)自己加上去的。
Cursor 把这个叫「归属(attribution)」,默认开着。CLI 的配置文件在用户目录下:
~/.cursor/cli-config.json
%USERPROFILE%\.cursor\cli-config.json
我打开一看,末尾果然有这么一段(字段名和官方文档对得上):
"attribution": { "attributeCommitsToAgent": true, "attributePRsToAgent": true } |
attributeCommitsToAgent
管提交署名,
attributePRsToAgent
管 PR 署名,默认都是
true
。
两个地方都能关,我建议都确认一遍,因为 IDE 改了不一定同步到 CLI。
图形界面:进
Cursor Settings → Agents → Attribution
,把 Commit Attribution 和 PR Attribution 都关掉。关完一定整个重启 Cursor,光重启终端没用——这点我吃过亏。
CLI 配置:直接改
~/.cursor/cli-config.json
,两个都设成
false
:
"attribution": { "attributeCommitsToAgent": false, "attributePRsToAgent": false } |
关掉之后,新提交就不会再带这行了。但历史里那一堆还在,得继续处理。
这一步要重写提交记录。提醒一句,我也是确认过才敢动:重写会改掉 commit hash,只在还没推送、没跟别人共享的提交上做才安全。已经 push 出去的分支别这么搞,否则要 force push,还会连累队友。
我只动「本地比远端多出来」的那些,已经发布的历史不碰:
# 看看本地领先远端几个提交 git rev-list --count origin/<分支>..HEAD # 挨个标出哪些带署名 for c in $(git rev-list origin/<分支>..HEAD); do if git log -1 --format='%B' "$c" | grep -q 'Co-authored-by: Cursor'; then m="[带]"; else m="[无]"; fi echo "$m $(git log -1 --format='%h %s' "$c")" done |
我这边是领先 15 个,其中 13 个带署名,最早两个是手动提交的、干净的。
直接在命令行里写删除逻辑,引号能把人逼疯,所以我把它扔进一个临时脚本:
cat > /tmp/strip_coauthor.sh <<'EOF' #!/bin/sh perl -0777 -pe 's/\n*Co-authored-by: Cursor <cursoragent\@cursor\.com>[ \t]*\n?//g' EOF chmod +x /tmp/strip_coauthor.sh FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f \ --msg-filter '/tmp/strip_coauthor.sh' \ origin/<分支>..HEAD |
我用
perl -0777
把整条 message 当一整块来处理,连署名行前面那个多余空行一起吃掉,提交结尾不会留下空行。
# 还带署名的未推送提交数,应该是 0 cnt=0 for c in $(git rev-list origin/<分支>..HEAD); do git log -1 --format='%B' "$c" | grep -q 'Co-authored-by: Cursor' && cnt=$((cnt+1)) done echo "$cnt" # 删掉临时脚本和 filter-branch 留下的备份引用 rm -f /tmp/strip_coauthor.sh git update-ref -d refs/original/refs/heads/<分支> |
我跑完输出是
0
,
git log
也干净了。确认没问题再正常
git push
就行,未推送的提交不需要 force。
git filter-branch
官方其实已经不推荐了,慢又容易出岔子。要是能装
git-filter-repo
,我更推荐它:
git filter-repo --message-callback ' return re.sub(rb"\n*Co-authored-by: Cursor <[email protected]>[ \t]*", b"", message) ' --refs origin/<分支>..HEAD |
我查的时候看到不少人反馈,有些 CLI 版本或者公司开了 Enterprise 的,本地配置会被无视,照样加。准备两手:
兜底一,仓库级 hook 强删。 这招最硬,提交前直接把那行删掉:
cat > .git/hooks/prepare-commit-msg <<'EOF' #!/bin/sh # macOS 用 sed -i '';Linux 把它换成 sed -i sed -i '' '/cursoragent@cursor\.com/d' "$1" EOF chmod +x .git/hooks/prepare-commit-msg |
.git/hooks/
不进版本控制,重新 clone 之后得再建一遍。
兜底二,给 AI 加条规则。 在
Cursor Settings → Rules for AI
或项目的
.cursor/rules
里写一句:
Never add "Made-with: Cursor", "Co-authored-by: Cursor", or any Cursor attribution/trailer to commits, PRs, or code comments. |
如果你是 Enterprise,团队后台可能强制开了归属,本地怎么改都没用,只能找管理员关。
cli-config.json
是用户级、全局的,会影响你所有项目;要是个别项目想留着署名,得单独处理。attribution.attributeCommitsToAgent
字段说明:https://docs.cursor.com/git filter-branch
:https://git-scm.com/docs/git-filter-branchgit-filter-repo
(更推荐的替代):https://github.com/newren/git-filter-repo关键词:Cursor、Co-authored-by、[email protected]、Git 提交署名、attributeCommitsToAgent、cli-config.json、git filter-branch、git filter-repo、移除 Cursor 署名、prepare-commit-msg。