跳转到主要内容
SourceTree 应用程序界面,显示 Git 仓库。

SourceTree 和 Git 设置

可选软件 Version 1.0.0

本指南将帮助您设置 SourceTree 和 Git,以便有效地管理您的 Astro Modular 博客。

安装 Git

Windows

  1. git-scm.com 下载 Git
  2. 运行安装程序
  3. 使用默认设置(除非您有特定需求)

macOS

  1. 安装 Xcode 命令行工具:xcode-select --install
  2. 或从 git-scm.com 下载

Linux

# Ubuntu/Debian
sudo apt-get update
sudo apt-get install git

# Fedora
sudo dnf install git

# Arch Linux
sudo pacman -S git

配置 Git

设置您的身份信息:

git config --global user.name "您的姓名"
git config --global user.email "your.email@example.com"

安装 SourceTree

  1. 访问 sourcetreeapp.com
  2. 下载适用于您操作系统的版本
  3. 运行安装程序
  4. 启动 SourceTree

初始化仓库

新博客

  1. 在 SourceTree 中,点击”创建”
  2. 选择”创建新仓库”
  3. 浏览到您的博客目录
  4. 点击”创建”

现有博客

  1. 在 SourceTree 中,点击”克隆”
  2. 输入仓库 URL
  3. 选择目标位置
  4. 点击”克隆”

设置 Astro 博客

  1. 打开您的博客目录
  2. 在终端中运行:
    npm install
    npm run dev
  3. 确认博客正常运行

配置部署

Netlify

  1. 在 Netlify 上创建账户
  2. 连接您的 Git 仓库
  3. 配置构建设置:
    • 构建命令:npm run build
    • 发布目录:dist

Vercel

  1. 在 Vercel 上创建账户
  2. 导入您的 Git 仓库
  3. 配置构建设置:
    • 构建命令:npm run build
    • 输出目录:dist

日常工作流

创建新文章

  1. src/content/posts 中创建新文件
  2. 添加前置元数据
  3. 撰写内容
  4. 在 SourceTree 中提交更改
  5. 推送到远程仓库

更新现有内容

  1. 编辑文件
  2. 在 SourceTree 中查看更改
  3. 提交更改
  4. 推送到远程仓库

高级 Git 工作流

分支策略

# 创建新分支
git checkout -b feature/new-feature

# 切换分支
git checkout main

# 合并分支
git merge feature/new-feature

# 删除分支
git branch -d feature/new-feature

解决冲突

  1. 在 SourceTree 中识别冲突文件
  2. 打开文件并解决冲突
  3. 标记为已解决
  4. 提交合并

备份和恢复

备份

  1. 在 SourceTree 中,点击”仓库”
  2. 选择”归档”
  3. 保存归档文件

恢复

  1. 在 SourceTree 中,点击”文件”
  2. 选择”从归档恢复”
  3. 选择归档文件

常见问题

推送被拒绝

# 拉取最新更改
git pull origin main

# 解决任何冲突
# 然后再次推送
git push origin main

忘记提交

# 查看更改
git status

# 添加所有更改
git add .

# 提交
git commit -m "您的提交信息"

# 推送
git push origin main

最佳实践

  1. 经常提交:小而频繁的提交更容易管理
  2. 写清晰的提交信息:描述您更改了什么以及为什么
  3. 使用分支:为新功能或重大更改使用分支
  4. 定期拉取:保持您的本地仓库与远程仓库同步
  5. 备份重要更改:在重大更改前创建备份

资源

就这样!您现在已准备好使用 SourceTree 和 Git 管理您的 Astro Modular 博客了。