Git提交代码注释信息规范-相关命令汇总

本文详述了Git的提交注释规范和常用命令,包括如何配置用户信息、管理文件状态、创建与切换分支、推送代码到远程仓库。同时强调了遵循提交流程的重要性,并提供了Windows操作系统下的基本命令操作指南,帮助开发者更高效地使用Git进行版本控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

- Git提交代码注释信息规范
  - git commit -m "提交类型+代码总结"
  - 提交类型:
    1. feat: 修改/增加新功能
    2. fix: 修改bug/功能代码的变更
    3. docs: 文档相关变更
    4. style: 不影响代码含义的变更(空白/格式/缺少符号等)
    5. refactor: 代码重构变更
    6. perf: 改进性能的变更
    7. test: 添加/修改现有的测试
    8. chore: Build/.gitignore/辅助工具/库(文档生成)等变更
  - Example: feat: support for async execution

- Git命令测试
  - 命令类型:
    1. git config --global user.name "用户名": 配置全局用户名变量
    2. git config --global user.email "用户邮箱": 配置全局用户邮箱变量
    3. git config --global --list: 查看全局全部配置变量
    4. git config --system --list: 查看系统全部配置变量
    5. git config --local --list: 查看本地全部配置变量
    6. git init: 初始化文件夹
    7. git clone 远程项目地址: 克隆远程项目到本地
    8. git status: 查看当前所有文件状态
    9. git add (路径)文件名.文件后缀: 添加文件到缓存区,可以用空格分开添加多个(状态: untracked file-new file,位置: .git文件夹)
    10. git add 文件夹: 添加文件夹下所有的文件到缓存区
    11. git add -A: (All)添加本目录所有文件到缓存区
    12. git add -A .: (All)添加所有改变文件(新添加/编辑过)到缓存区
    13. git add -u: (update)添加所有更新文件(编辑过)到缓存区
    14. git rm -cache (路径)文件名.文件后缀: 从缓存区删除指定文件(状态: new file-untracked file,位置: 工作空间)
    15. git rm (路径)文件名.文件后缀: 工作空间中删除文件(直接文件夹中删除)
    16. git reset --hard: 恢复上一步骤(可以恢复删除的文件或重命名后被删除的文件)
    17. git commit -m "姓名拼音+提交类型+代码总结": 提交文件到本地仓库(位置: .git文件夹)
    18. git remote add 远程仓库名称(origin) Gitee/GitLab/GitHub远程仓库地址: 绑定远程仓库地址
    19. git remote remove 绑定的远程仓库名称: 删除绑定的远程仓库地址
    20. git remote: 查看绑定的远程仓库名称
    21. git remote -v: (verbose)查看绑定的远程仓库信息(名称+地址)
    22. git log: 打印git的详细操作日志(Enter继续打印)
    23. git log -n2: 打印git的前两条详细操作日志
    24. git log --oneline: 打印git的简略操作日志
    25. git log --oneline -n2: 打印git的前两条简略操作日志
    26. q: 退出当前git命令(如查看日志)
    27. git branch: 查看绑定的远程仓库的分支名称(*为当前使用分支)
    28. git branch -v: 查看绑定的远程仓库的分支信息
    29. git branch 新建分支名称: 新建分支
    30. git branch -d 删除分支名称: 删除分支(不能删除当前使用分支,需先切换出来)
    31. git checkout 切换目标分支名称: 切换分支
    32. git push 绑定的远程仓库名称 推送的新分支名称(和本地名称一致): 推送新分支,将本目录的文件推送到远程仓库的新分支上
    33. git push 绑定的远程仓库名称 本地分支名称:推送的新分支名称: 推送新分支,没有则建新分支,有则更新数据
    34. git push: 更新数据(推送当前分支)
    35. git checkout --track 绑定的远程仓库名称/拉取分支名称: 拉取远程仓库的特定分支(仅可拉取本地推送的分支,且本地不存在此分支名称)
    36. git push 绑定的远程仓库名称 :删除分支名称: 删除远程仓库分支
    37. git push 绑定的远程仓库名称 删除分支名称 --delete: 删除远程仓库分支

  - 总结:
    1. 用cmd代替PowerShell运行命令,因为兼容性前者好
    2. 严格遵守推送流程:workspace(工作空间)-index(缓存)-repository(本地仓库)-remote(远程仓库)

- Windows命令:
  1. cd ..: 返回上一级目录
  2. cd 相对本路径: 由本位置转到相对的下级路径目录
  3. cd 任意绝对路径: 重新定位到绝对路径目录
  4. mkdir 文件夹名: 创建文件夹
  5. type nul>文件名.文件后缀名: 创建文件(cmd生效,PowerShell不生效)
  6. dir/ls: 查看当前的路径和文件列表
  7. clear/cls: 清空屏幕
  8. tab: 本目录搜索补全文件名.后缀名
  9. ^: 上翻命令
  10. ^C(Ctrl+C): 退出当前命令
  11. rename 旧文件名.文件后缀 新文件名.文件后缀: 重命名文件名(cmd生效,PowerShell不生效)
public function importExcel(): Json { // 设置脚本执行时间无限制,避免大数据处理超时 set_time_limit(0); // 设置脚本最大内存使用量为2GB,处理大文件时避免内存溢出 ini_set('memory_limit', '2048M'); // 获取请求参数(包含上传的文件信息) $params = $this->request->param(); // 验证文件是否上传 if (empty($params["file"])) { return $this->fail('请上传要导入文件'); } // 定义Excel表头与数据库字段的映射关系 $titleArr = [ '商家编号' => 'merchant_code', '业务单号' => 'business_order_number', '平台订单号' => 'platform_order_number', '商家订单号' => 'merchant_order_number', '退回件关联运单号' => 'return_waybill_number', '店铺名称' => 'shop_name', '下单时间' => 'order_time', '始发省' => 'origin_province', '始发市' => 'origin_city', '目的省' => 'destination_province', '目的市' => 'destination_city', '计费重量' => 'billing_weight', '实际重量(kg)' => 'actual_weight_kg', '实际体积(cm3)' => 'actual_volume_cm3', '首重单价' => 'first_weight_price', '续重单价' => 'continued_weight_price', '包裹/耗材数量' => 'package_material_quantity', '销售平台订单号' => 'sales_platform_order_number', '费用类型' => 'fee_type', '原始金额' => 'original_amount', '折扣/促销金额' => 'discount_promotion_amount', '计费时间' => 'billing_time', '结算金额' => 'settlement_amount', '签收时间' => 'sign_time', '商品编码' => 'product_code', '商品名称' => 'product_name' ]; try { // 构建上传文件的完整路径 $path = app()->getRootPath() . "public/" . $params['file']; // 1. 创建Excel读取器并设置为只读取数据模式(优化内存) $reader = IOFactory::createReaderForFile($path); $reader->setReadDataOnly(true); // 2. 获取工作表基本信息(总行数和最大列字母),避免加载整个文件 $worksheetInfo = $reader->listWorksheetInfo($path); $totalRows = $worksheetInfo[0]['totalRows']; $highestColumn = $worksheetInfo[0]['lastColumnLetter']; // 3. 读取表头行(仅加载第一行数据) $chunkFilter = new ChunkReadFilter(); $chunkFilter->setRows(1, 1); $reader->setReadFilter($chunkFilter); $spreadsheet = $reader->load($path); $sheet = $spreadsheet->getSheet(0); $title = $sheet->rangeToArray('A1:' . $highestColumn . '1', null, true, true, true)[1]; // 释放不再使用的Spreadsheet对象,减少内存占用 $spreadsheet->disconnectWorksheets(); unset($spreadsheet); // 检查表头是否存在 if (empty($title)) { throw new \Exception('Excel表头为空'); } // 初始化数据库模型和计数器 $model = new DeliveryPrimaryRegionsItemizationModel(); //TODO:根据自身mysql所在服务的性能来控制批量插入大小 不然报错或者导入很慢 该值需要反复测验找到最合适的大小 $insertBatchSize = 2000; // 数据库插入批次大小 $total = 0; // 总记录数 $success = 0; // 成功处理记录数 $failedBatches = []; // 失败批次记录 $batchData = []; // 批次数据临时存储 $processedRows = 0; // 已处理行数 // 4. 分块处理Excel数据,每次处理$chunkSize行 //TODO:根据自身服务器性能来决定每次分块读取excel表格数据的条数 不然报错或者导入很慢 该值需要反复测验找到最合适的大小 $chunkSize = 5000; // 每次加载5000行 $chunkFilter = new ChunkReadFilter(); $reader->setReadFilter($chunkFilter); // 循环处理每个数据块 for ($startRow = 2; $startRow <= $totalRows; $startRow += $chunkSize) { $endRow = min($startRow + $chunkSize - 1, $totalRows); $chunkFilter->setRows($startRow, $chunkSize); // 5. 加载当前数据块 $spreadsheet = $reader->load($path); $sheet = $spreadsheet->getSheet(0); // 6. 处理当前块中的每一行数据 for ($row = $startRow; $row <= $endRow; $row++) { // 获取当前行数据 $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, true, true)[$row]; $item = []; // 将Excel列名映射为数据库字段名 foreach ($rowData as $colIndex => $value) { $colName = $title[$colIndex] ?? ''; if ($colName && isset($titleArr[$colName])) { $item[$titleArr[$colName]] = trim($value ?? ''); // 原始值去除首尾空格 } } // print_r($item);die; // 如果行数据不为空,则添加到批次数据中 if (!empty($item)) { $batchData[] = $item; $processedRows++; } // 7. 当批次数据达到插入批次大小时,执行数据库插入操作 if (count($batchData) >= $insertBatchSize) { $this->processBatch($model, $batchData, $success, $failedBatches, $total); $batchData = []; // 清空批次数据 } $total++; // 总记录数递增 } // 8. 释放当前数据块占用的内存 $spreadsheet->disconnectWorksheets(); unset($spreadsheet); gc_collect_cycles(); // 触发垃圾回收 // 9. 输出处理进度信息 $progress = round(($endRow / $totalRows) * 100, 2); echo "处理进度: {$progress}% | 已处理: {$processedRows} 行\n"; } // 10. 处理剩余不足一个批次的数据 if (!empty($batchData)) { $this->processBatch($model, $batchData, $success, $failedBatches, $total); } // 返回处理结果 if (empty($failedBatches)) { $resultMsg = "导入成功,共{$total}条数据,成功导入{$success}条"; return $this->success($resultMsg); } else { $errorCount = $total - $success; $errorMsg = "失败 {$errorCount} 条,第一个错误: {$failedBatches[0]['error']}"; return $this->fail('导入失败', ['remark' => $errorMsg]); } } catch (\Exception $e) { // 异常处理,返回错误信息 return $this->fail('导入过程中出错: ' . $e->getMessage()); } } /** * 处理数据批次(优化SQL构建) */ private function processBatch($model, &$batchData, &$success, &$failedBatches, &$total) { // 如果批次数据为空则直接返回 if (empty($batchData)) return; try { // 使用参数绑定构建SQL语句,防止SQL注入 $tableName = $model->getTable(); $fields = array_keys($batchData[0]); $fieldList = '`' . implode('`, `', $fields) . '`'; $placeholders = '(' . implode(',', array_fill(0, count($fields), '?')) . ')'; $sql = "INSERT INTO {$tableName} ({$fieldList}) VALUES "; $values = []; $params = []; // 构建批量插入的SQL语句和参数数组 foreach ($batchData as $row) { $values[] = $placeholders; foreach ($fields as $field) { $params[] = $row[$field] ?? null; } } $sql .= implode(',', $values); // 执行带参数绑定的SQL语句 // 一定不要使用模型去操作数据库 不然效率很低 原生的最好! Db::execute($sql, $params); // 更新成功记录数 $success += count($batchData); // 清空批次数据 $batchData = []; } catch (\Exception $e) { // 记录失败批次信息 $failedBatches[] = [ 'startRow' => $total - count($batchData) + 1, 'endRow' => $total, 'error' => $e->getMessage() ]; // 出错时清空批次数据,避免重复处理 $batchData = []; } } /** * 分块读取过滤器 * 用于控制只读取Excel文件中的指定行范围 * common.php代码规范导致本地git有差异直接还原 直接写在控制器里算了! */ class ChunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { private $startRow = 0; private $endRow = 0; // 设置要读取的起始行和行数 public function setRows($startRow, $chunkSize) { $this->startRow = $startRow; $this->endRow = $startRow + $chunkSize; } // 判断当前单元格是否应该被读取 public function readCell($column, $row, $worksheetName = '') { // 只读取指定范围内的行 if ($row >= $this->startRow && $row <= $this->endRow) { return true; } return false; } } 导入非常的慢,慢的不行,另外我的excel表格当中的数据量为30万条,并且字段26个文字也特别多 ,怎么办呢?有什么可以优化的地方吗我的代码里面?如果可以优化提升性能请为我提供完整的代码,不要忘记注释信息
最新发布
07-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BB-X

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值