Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: simple-git-hooks的钩子很容易导致合并分支失败 #500

Closed
NHZEX opened this issue Jun 16, 2024 · 9 comments
Closed

[Bug]: simple-git-hooks的钩子很容易导致合并分支失败 #500

NHZEX opened this issue Jun 16, 2024 · 9 comments

Comments

@NHZEX
Copy link
Contributor

NHZEX commented Jun 16, 2024

软件版本

1.2.5

运行环境

Windows (64)

运行架构

x86

重现步骤

通过ide操作分支合并上游提交并解决冲突。

当前对启用的钩子做了一定调整

"simple-git-hooks": {
    "commit-msg": "pnpm sa git-commit-verify",
    "pre-commit": "pnpm lint-staged"
}

git log

16:54:09.732: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false merge refs/remotes/upstream/main
error: Your local changes to the following files would be overwritten by merge:
	package.json
Please commit your changes or stash them before you merge.
Aborting
Merge with strategy ort failed.
16:54:13.380: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false restore --staged --worktree --source=HEAD -- package.json src/typings/app.d.ts src/hooks/common/form.ts src/locales/index.ts src/locales/langs/en-us.ts src/locales/langs/zh-cn.ts build/plugins/index.ts packages/scripts/src/commands/git-commit.ts
16:54:13.732: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false merge refs/remotes/upstream/main
16:55:21.037: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f --sparse -- src/typings/global.d.ts
16:56:43.822: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f --sparse -- src/store/modules/auth/index.ts
16:57:26.216: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f --sparse -- pnpm-lock.yaml
16:57:26.691: [soybean-admin] git -c core.quotepath=false -c log.showSignature=false commit -F <project-path>\.git\MERGE_MSG --
[STARTED] Preparing lint-staged...
[COMPLETED] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 20 files
[STARTED] * — 20 files
[STARTED] eslint --fix
[COMPLETED] eslint --fix
[COMPLETED] * — 20 files
[COMPLETED] package.json — 20 files
[COMPLETED] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[COMPLETED] Applying modifications from tasks...
[STARTED] Cleaning up temporary files...
[COMPLETED] Cleaning up temporary files...
<project-path>\packages\scripts\src\commands\git-commit.ts:80
    throw new Error(
          ^
Error:  ERROR  git commit message must match the Conventional Commits standard!
Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.
Get more info about Conventional Commits, follow this link: https://conventionalcommits.org
    at gitCommitVerify (<project-path>\packages\scripts\src\commands\git-commit.ts:80:11)
    at CAC.action (<project-path>\packages\scripts\src\index.ts:71:9)
Node.js v20.14.0

MERGE_MSG

Merge remote-tracking branch 'refs/remotes/upstream/main' into dev/4.x

# Conflicts:
#	pnpm-lock.yaml
#	src/store/modules/auth/index.ts
#	src/typings/global.d.ts

期望的结果是什么?

确保钩子不会对 Git 各种操作 mergerebase 造成负面影响,手动恢复起来挺麻烦的。

实际的结果是什么?

合并被中断,得手动恢复

日志记录(可选)

No response

补充说明(可选)

No response

@honghuangdc
Copy link
Member

用git rebase去解决

@honghuangdc honghuangdc closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2024
@NHZEX
Copy link
Contributor Author

NHZEX commented Jun 16, 2024

用git rebase去解决

这方案不太行,已经分叉开始项目了,merge操作方便跟踪上游框架更新,项目是得保留完整的提交记录。
rebase在这个场景下不合适,对提交记录的破坏和冲突解决处理都是麻烦。
我觉得如果是 PR 贡献这个场景rebase是合适的。

@honghuangdc
Copy link
Member

从指定commit 创建分支git branch
git cherry-pick
git rebase
解决git rebase的冲突

基本用不上git merge

@honghuangdc
Copy link
Member

从指定commit 创建分支git branch
git cherry-pick
git rebase
解决git rebase的冲突

基本用不上git merge

就算是用git merge,也能后编辑commit信息

@honghuangdc
Copy link
Member

SoybeanAdmin 的example分支每次更新版本都是从main分支merge,有冲突时就解决冲突,和提交信息也没关系

@NHZEX
Copy link
Contributor Author

NHZEX commented Jun 16, 2024

SoybeanAdmin 的example分支每次更新版本都是从main分支merge,有冲突时就解决冲突,和提交信息也没关系

这种是项目内的分支,当然没问题很合理,如果我提 PR 也会这样操作的,推送前看到看 master 是否有更改,有更改就 rebase 再后测试没问题在推送。

但我提到的是 fork 后的项目,同时保留上游追踪。

  • rebase 来合入更新就不可能考虑了,会改变hash,作为项目来说主分支的提交hash怎么可能去改变呢。
  • cherry-pick 会失去跟踪目的,不考虑。
  • merge 时编辑 message,不太可能考虑,因为 工具自动生成的消息是很清晰明了的。什么分支合并到什么分支,解决那些文件的冲突,我加个特定格式的头部并没有什么意义。

我还是提意,使用这种方案:https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/is-ignored/src/defaults.ts#L17-L28

[
	test(
		/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m
	),
	test(/^(R|r)evert (.*)/),
	test(/^(fixup|squash)!/),
	isSemver,
	test(/^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))/),
	test(/^Merge remote-tracking branch(\s*)(.*)/),
	test(/^Automatic merge(.*)/),
	test(/^Auto-merged (.*?) into (.*)/),
];

Copy link
Member

正好需要对commit的信息支持中文,这几个可以一并加进去

@honghuangdc
Copy link
Member

你提个issues,git-commit-verify命令对提交信息的校验支持忽略 merge 相关的信息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants