不允许还有人不会给开源项目提交代码
前言
近期为了面试也是一直在看Vue3的部分源码实现思路,再结合AI可以很好的了解到一些源码的具体实现过程,这样在应对面试过程中也能做到举一反三,话不多说,直接上干货!!!
1. Fork 项目到自己的 GitHub 账号
在 GitHub 上点击 Fork 按钮
2. Clone 自己的 fork 到本地
git clone github.com/YOUR_USERNA…
3. 设置远程仓库
git remote add upstream github.com/original/re… # 添加上游仓库
git remote set-url origin github.com/YOUR_USERNA… # 设置你的 fork
创建新分支 git checkout -b fix-name # 分支名应该反映改动内容
2. 安装依赖
pnpm install # Vue 使用 pnpm
3. 进行代码修改
修改相关文件
4. 运行测试(非必须)
pnpm test
提交信息格式:
type(scope): description
类型(type):
- fix: 修复bug
- feat: 新功能
- docs: 文档改动
- style: 代码格式改动
- refactor: 重构
- test: 测试相关
- chore: 构建过程或辅助工具的变动
示例:
git add .
git commit -m "fix(compiler-sfc): correct method name in templateUtils"
这里意思就是提交了一个修改的正确方法名在templateUtils
1. 推送到你的 fork
git push origin fix-name
2. 在 GitHub 上创建 PR
- 使用清晰的标题(与 commit 消息一致)
- 写详细的描述
- 确保选择正确的基础分支
标题
fix(compiler-sfc): correct method name in templateUtils
描述
Problem
- Describe the issue you're fixing
Solution
- Explain your changes
- What was changed and why
Additional Info
- Any side effects?
- Testing done?
- Screenshots (if UI changes)?
注意事项
- 确保一个 PR 只做一件事
- 遵循项目的代码风格
- 保持 commit 历史清晰
- 及时响应 review 意见
- 保持耐心,维护者可能比较忙
更新 fork 与上游同步
- git fetch upstream
- git checkout main
- git merge upstream/main
压缩/整理 commit
git rebase -i HEAD~n # n是要合并的commit数量
如果需要修改 PR
- git add .
- git commit --amend # 修改最后一次提交
- git push origin fix-name -f # 强制推送(谨慎使用)