demo/GIT.md

130 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Git 基础使用说明(零基础)
面向 [DKFile Source Git](https://git.dkfile.net/) 用户。
目标:会**创建仓库**、**克隆**、**提交推送**、**换电脑同步**、**改坏了回退**。
---
## 0. 核心好处
先养成「改完一小段就提交」的习惯。一旦改坏了,用历史记录**回退**即可。其它电脑执行 `git pull` 即可同步。
口诀:**改完 push换电脑 pull改坏了回退。**
---
## 1. 登录本站并创建仓库
1. 打开 https://git.dkfile.net/ VIP 可用「用 DKFile 登录」。
2. 点击右上角「**+**」或「新建仓库」。
3. 填写**仓库名称**(例如 `my-project`)。
4. 可见性建议选**私有**。
5. 可勾选「使用 README 初始化」;空仓从本机首次推送也可以不勾。
6. 创建成功后复制仓库地址,形如:
```text
https://git.dkfile.net/你的用户名/仓库名.git
```
不会操作时联系 **IDO老徐**
---
## 2. 安装 Git本机
```bash
# macOS已装 Homebrew 时)
brew install git
# Windowshttps://git-scm.com/downloads 安装后打开「Git Bash」
git --version
```
---
## 3. 第一次配置身份(每台电脑执行一次)
```bash
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"
```
---
## 4. 把仓库克隆到本机
```bash
git clone https://git.dkfile.net/你的用户名/仓库名.git
cd 仓库名
```
- 用户名 = 本站 Git 账号
- 密码建议用:**设置 → 应用 → Access Token**(不要用登录密码硬扛)
也可先克隆本演示仓练手:
```bash
git clone https://git.dkfile.net/dkfile/demo.git
cd demo
```
---
## 5. 日常:拉取 → 提交 → 推送
```bash
git pull
git add .
git status
git commit -m "说明本次改了什么"
git push
```
建议提交说明写清楚「改了什么」,方便以后回退时辨认。
---
## 6. 换任何一台电脑:拉取最新代码
```bash
# 新电脑第一次
git clone https://git.dkfile.net/你的用户名/仓库名.git
# 之后每次
cd 仓库名
git pull
```
---
## 7. 改坏了:回退到之前的版本
前提:之前已经 `git commit` 提交过。
```bash
# 1看历史
git log --oneline
# 2只恢复某一个文件推荐
git checkout 提交编号 -- 文件路径
git add .
git commit -m "回退某文件到指定版本"
git push
# 3整个项目回到某个历史版本慎用
git reset --hard 提交编号
# 需要服务器也回去时(覆盖远端,更慎用)
git push --force
```
也可在网页仓库的「提交」列表查看历史。拿不准时联系 **IDO老徐**
---
## 8. 建议
- 业务代码仓库保持**私有**。
- 本演示仓 `dkfile/demo` 仅作公开说明与练手,勿推密钥、密码、客户数据。
- 更多产品说明见 [ABOUT-DKFILE.md](./ABOUT-DKFILE.md) 与 [DKFile 官网](https://dkfile.net/)。