默认请求:composer require alipaysdk/easysdk
切换php版本请求:php8 D:\soft\phpstudy_pro\Extensions\composer2.5.8\composer.phar require alipaysdk/easysdk
php8 环境变量中的php8版本
D:softphpstudy_proExtensionscomposer2.5.8composer.phar composer对应的composer.phar

以下是 Git 的常用命令分类整理,覆盖日常开发中的核心操作场景:


一、仓库初始化与克隆

  1. git init
    初始化本地 Git 仓库,生成 .git 目录。

    git init
  2. git clone <url>
    克隆远程仓库到本地,支持 SSH/HTTPS 协议。

    git clone https://github.com/user/repo.git

二、提交与同步

  1. git add
    将文件添加到暂存区(Staging Area)。

    git add .           # 添加所有修改
    git add file.txt    # 添加单个文件
  2. git commit
    提交暂存区的修改到本地仓库。

    git commit -m "提交说明"    # 常规提交
    git commit -am "快速提交"   # 跳过暂存,直接提交跟踪过的文件
  3. git push
    推送本地提交到远程仓库。

    git push origin main
  4. git pull
    拉取远程仓库最新代码并合并到当前分支(相当于 git fetch + git merge)。

    git pull origin main
  5. git fetch
    仅下载远程仓库的更新,不自动合并(需手动 git merge)。

    git fetch --all

三、分支管理

  1. git branch
    查看、创建或删除分支。

    git branch               # 列出本地分支
    git branch -a            # 列出所有分支(本地+远程)
    git branch new-feature   # 创建新分支
    git branch -d old-branch # 删除分支
  2. git checkout
    切换分支或恢复文件。

    git checkout main        # 切换到 main 分支
    git checkout -b dev      # 创建并切换到 dev 分支
  3. git merge
    合并指定分支到当前分支。

    git merge dev          # 将 dev 分支合并到当前分支

四、状态与差异

  1. git status
    查看工作区和暂存区的文件状态。

    git status
  2. git diff
    比较文件修改内容。

    git diff             # 比较工作区与暂存区
    git diff --staged    # 比较暂存区与最新提交
    git diff HEAD~1      # 比较当前与上一次提交

五、撤销与恢复

  1. git reset
    撤销提交或取消暂存。

    git reset HEAD~1         # 回退到上一次提交(保留修改)
    git reset --hard HEAD~1  # 强制回退并丢弃修改
  2. git restore
    恢复文件到指定状态(Git 2.23+ 新增)。

    git restore file.txt      # 恢复工作区文件到最近提交
    git restore --staged file.txt # 取消暂存
  3. git stash
    临时保存未提交的修改。

    git stash          # 暂存当前修改
    git stash pop      # 恢复最近一次暂存的修改

六、历史与标签

  1. git log
    查看提交历史。

    git log --oneline    # 简洁模式
    git log --graph      # 图形化分支历史
  2. git tag
    管理版本标签。

    git tag v1.0.0       # 创建标签
    git push --tags      # 推送所有标签到远程

七、远程仓库

  1. git remote
    管理远程仓库关联。

    git remote -v         # 查看关联的远程仓库
    git remote add origin <url>  # 添加远程仓库

常用场景示例


以上命令覆盖了 Git 日常使用的 90% 场景。如需更详细操作(如 git rebasegit cherry-pick 等),可参考 Git 官方文档或相关教程 11(https://www.cnblogs.com/kenshinobiy/p/4543976.html)23(https://blog.csdn.net/m0_45234510/article/details/120181503)

我来介绍 ThinkPHP 8 实现一个安全的 API 的完整流程:

1. 首先创建项目并安装必要依赖

composer create-project topthink/think tp8
cd tp8
composer require topthink/think-migration

2. 创建数据表迁移文件

php think make:migration create_users_table

php:database/migrations/xxx_create_users_table.php

<?php
use think\migration\Migrator;

class CreateUsersTable extends Migrator
{
    public function change()
    {
        $this->table('users')
            ->addColumn('username', 'string', ['limit' => 50])
            ->addColumn('password', 'string', ['limit' => 255])
            ->addColumn('api_token', 'string', ['limit' => 100, 'null' => true])
            ->addColumn('status', 'boolean', ['default' => 1])
            ->addColumn('create_time', 'timestamp', ['null' => true])
            ->addColumn('update_time', 'timestamp', ['null' => true])
            ->create();
    }
}

- 阅读剩余部分 -

让我解释一下 @click="deleteAll"@click="deleteAll()" 的区别:

  1. 不加括号 @click="deleteAll"
<text class="delete" @click="deleteAll">清空</text>

// 这种写法会:
// 1. 自动传入事件对象 event 作为第一个参数
// 2. 当点击时才调用函数
function deleteAll(event) {
    console.log(event)  // 可以获取到事件对象
    // 执行清空逻辑
}
  1. 加括号 @click="deleteAll()"
<text class="delete" @click="deleteAll()">清空</text>

// 这种写法:
// 1. 不会自动传入事件对象
// 2. 当点击时调用函数
function deleteAll() {
    // 无法获取事件对象
    // 执行清空逻辑
}
  1. 如果需要同时获取事件对象和传参
<!-- 方法一:使用 $event -->
<text @click="deleteAll($event, otherParam)">清空</text>

<!-- 方法二:使用内联函数 -->
<text @click="(event) => deleteAll(event, otherParam)">清空</text>

function deleteAll(event, otherParam) {
    console.log(event)      // 事件对象
    console.log(otherParam) // 其他参数
}

在你的场景中:

  • 如果不需要使用事件对象,两种写法都可以
  • 如果需要事件对象(比如阻止冒泡),建议用不加括号的写法

建议:

  • 一般情况下不加括号更简洁
  • 需要传参时才加括号
  • 需要事件对象时不加括号

让我帮你理解 TypeScript 代码,通过对比来学习:

  1. 基础类型定义
// 没用 TS 时
let price = 88
let name = '红烧肉'

// 用了 TS 后
let price: number = 88         // 意思是:price 只能是数字
let name: string = '红烧肉'    // 意思是:name 只能是字符串
  1. 对象类型定义
// 没用 TS 时
const dish = {
    name: '红烧肉',
    price: 88,
    isSpicy: true
}

// 用了 TS 后
interface Dish {              // interface 相当于定义一个"模板"
    name: string;            // 规定 name 必须是字符串
    price: number;          // 规定 price 必须是数字
    isSpicy: boolean;      // 规定 isSpicy 必须是布尔值
}

const dish: Dish = {        // 告诉 TS:这个对象必须符合 Dish 的格式
    name: '红烧肉',
    price: 88,
    isSpicy: true
}
  1. 数组类型定义
// 没用 TS 时
const prices = [88, 66, 128]
const dishes = ['红烧肉', '青椒肉丝']

// 用了 TS 后
const prices: number[] = [88, 66, 128]     // 数组里只能放数字
const dishes: string[] = ['红烧肉', '青椒肉丝']  // 数组里只能放字符串
  1. 函数类型定义
// 没用 TS 时
function calculateTotal(price, quantity) {
    return price * quantity
}

// 用了 TS 后
function calculateTotal(price: number, quantity: number): number {
    return price * quantity
}
// 意思是:
// 1. price 必须是数字
// 2. quantity 必须是数字
// 3. 返回值必须是数字
  1. Vue 组件中的应用
// 没用 TS 时
const count = ref(0)
const message = ref('')

// 用了 TS 后
const count = ref<number>(0)      // count 只能是数字
const message = ref<string>('')   // message 只能是字符串
  1. 事件处理
// 没用 TS 时
function handleClick(event) {
    console.log(event.target.value)
}

// 用了 TS 后
function handleClick(event: MouseEvent): void {
    const target = event.target as HTMLInputElement  // 告诉 TS:这是一个输入框
    console.log(target.value)
}

学习建议:

  1. 循序渐进

    • 先理解基础类型(string, number, boolean)
    • 再学习对象和数组的类型定义
    • 最后学习接口和泛型
  2. 从简单开始
// 第一步:添加基础类型
let price: number = 88
let name: string = '红烧肉'

// 第二步:添加对象类型
interface MenuItem {
    name: string
    price: number
}

// 第三步:添加数组类型
const menu: MenuItem[] = [
    { name: '红烧肉', price: 88 },
    { name: '青椒肉丝', price: 66 }
]
  1. 使用 VS Code
  • 安装 TypeScript 插件
  • 鼠标悬停可以看到类型提示
  • 代码补全更智能
  1. 常见错误理解
// ❌ 错误示例
const price: number = "88"  // 错误:字符串不能赋值给数字类型

// ✅ 正确示例
const price: number = 88    // 正确:数字类型

记住:

  • TypeScript 主要是帮助我们避免错误
  • 类型定义就像是"约定"
  • 代码看起来复杂了,但更安全了
  • 开发时会有更好的提示

如果你觉得某段代码看不懂,可以:

  1. 去掉类型声明,看纯 JavaScript 逻辑
  2. 一点点加入类型,理解每个类型的作用
  3. 使用 VS Code 的类型提示功能