Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
studyweb
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
project
studyweb
Commits
ac38c097
提交
ac38c097
authored
7月 07, 2026
作者:
zhangqianwei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cfm_完成1.1.2 克隆项目
上级
913a48da
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
73 行增加
和
18 行删除
+73
-18
模块一-Python工程化.md
docs/Python工程化/模块一-Python工程化.md
+73
-18
没有找到文件。
docs/Python工程化/模块一-Python工程化.md
浏览文件 @
ac38c097
...
@@ -293,7 +293,9 @@ A:GitHub 提供了 noreply 邮箱(`username@users.noreply.github.com`),
...
@@ -293,7 +293,9 @@ A:GitHub 提供了 noreply 邮箱(`username@users.noreply.github.com`),
## 1.1.2 克隆项目
## 1.1.2 克隆项目
### 什么是克隆(clone)? 一句话定义
### 什么是克隆(clone)?
#### 一句话定义
`git clone <仓库地址>`
把远程仓库的
**完整历史**
复制到本地,生成一个全新的工作目录。
`git clone <仓库地址>`
把远程仓库的
**完整历史**
复制到本地,生成一个全新的工作目录。
...
@@ -380,12 +382,10 @@ ssh -T git@github.com
...
@@ -380,12 +382,10 @@ ssh -T git@github.com
### 克隆到指定目录
### 克隆到指定目录
```
bash
```
bash
# 克隆并改名
# 克隆并改名
(自动进入新目录)
git clone git@github.com:user/repo.git my-project
git clone git@github.com:user/repo.git my-project
cd
my-project
# 克隆到当前空目录(注意末尾的点)
# 克隆到当前空目录(注意末尾的点,适用于已 mkdir 的空目录)
mkdir
my-project
&&
cd
my-project
git clone git@github.com:user/repo.git
.
git clone git@github.com:user/repo.git
.
```
```
...
@@ -396,7 +396,41 @@ git clone git@github.com:user/repo.git .
...
@@ -396,7 +396,41 @@ git clone git@github.com:user/repo.git .
git clone
--depth
1 git@github.com:user/repo.git
git clone
--depth
1 git@github.com:user/repo.git
# 后续如需看完整历史:
# 后续如需看完整历史:
# git fetch --unshallow
git fetch
--unshallow
```
### 克隆指定分支
```
bash
# 方法 1:克隆后切换到指定分支
git clone
--depth
1 git@github.com:user/repo.git
git switch develop
# 克隆默认是 main,改切到 develop
# 方法 2:直接克隆指定分支(适合分支很多的大型项目)
git clone
--branch
develop git@github.com:user/repo.git
```
### 克隆后的标准流程
```
bash
# 1. 进入仓库目录
cd
my-project
# 2. 查看克隆后的状态(自动配置好了 origin 远程)
git remote
-v
# origin git@github.com:user/repo.git (fetch)
# origin git@github.com:user/repo.git (push)
# 3. 查看当前分支
git branch
-a
# * main
# remotes/origin/HEAD -> origin/main ← 默认分支
# remotes/origin/develop
# remotes/origin/feature/xxx
# 4. 克隆后第一件事:配置你的身份(见 1.1.1)
git config user.name
"张三"
git config user.email
"zhangsan@company.com"
```
```
---
---
...
@@ -407,20 +441,38 @@ git clone --depth 1 git@github.com:user/repo.git
...
@@ -407,20 +441,38 @@ git clone --depth 1 git@github.com:user/repo.git
A:SSH Key 没配好。检查:
A:SSH Key 没配好。检查:
1.
私钥路径对不对:
`ls ~/.ssh/id_ed25519`
1.
私钥路径对不对:
`ls ~/.ssh/id_ed25519`
(Linux/Mac)或
`ls ~/.ssh/id_rsa`
(Windows)
2.
公钥是否已加到 GitHub:
`cat ~/.ssh/id_ed25519.pub`
2.
公钥是否已加到 GitHub:
`cat ~/.ssh/id_ed25519.pub`
3.
SSH agent 加载了没有:
`ssh-add ~/.ssh/id_ed25519`
3.
SSH agent 加载了没有(Linux/Mac):
```
bash
ssh-add ~/.ssh/id_ed25519
```
4. Windows 用户:用
"Git Bash"
或设置 Pageant 等 SSH agent
**
Q:克隆很慢/超时?
**
**
Q:克隆很慢/超时?
**
A:
换协议试试
:
A:
几种解决方案
:
```
bash
1. 换协议试试(在国内 SSH 通常比 HTTPS 快):
# 用 SSH 替代 HTTPS(在国内通常更快)
git clone git@github.com:user/repo.git
```
bash
```
git clone git@github.com:user/repo.git
```
2. 配代理(如果有梯子):
```
bash
git config
--global
http.proxy http://127.0.0.1:7890
git config
--global
https.proxy http://127.0.0.1:7890
```
3. 用国内镜像(如 Gitee)先 fork 再克隆
**
Q:GitHub 限制单个仓库 100MB,克隆大仓库失败?
**
A:GitHub 对大文件有限制。如果仓库包含大文件:
或者配 git proxy:
`git config --global http.proxy http://127.0.0.1:7890`
1. 先用浅克隆:
`
git clone
--depth
1 <url>
`
2. 如果是 Git LFS 仓库:
`
git lfs
install
`
后再克隆
3. 联系仓库管理员清理大文件或用 Git LFS 管理
**
Q:克隆完发现忘了
--depth
,怎么补全历史?
**
**
Q:克隆完发现忘了
--depth
,怎么补全历史?
**
...
@@ -438,8 +490,10 @@ git fetch --unshallow
...
@@ -438,8 +490,10 @@ git fetch --unshallow
☐ 能用 git clone
<ssh-url>
把项目拉下来
☐ 能用 git clone
<ssh-url>
把项目拉下来
☐ 能区分 HTTPS 和 SSH 两种协议的使用场景
☐ 能区分 HTTPS 和 SSH 两种协议的使用场景
☐ 能生成 SSH Key 并配置到 GitHub
☐ 能生成 SSH Key 并配置到 GitHub
☐ 知道克隆后
默认进入 master/main 分支
☐ 知道克隆后
远程 origin 自动配置好,查看用 git remote -v
☐ 能用 --depth 1 做浅克隆,并能用 --unshallow 补全历史
☐ 能用 --depth 1 做浅克隆,并能用 --unshallow 补全历史
☐ 能用 --branch 克隆指定分支
☐ 知道克隆后要配置 git 身份信息
```
```
## 官方来源
## 官方来源
...
@@ -449,11 +503,12 @@ git fetch --unshallow
...
@@ -449,11 +503,12 @@ git fetch --unshallow
## 参考文献
## 参考文献
[
1
]
*Pro Git*
第 2.1 节 "获取帮助"。
[1] Scott Chacon & Ben Straub. *Pro Git (2nd Edition)*. Apress, 2014. 第 2.1 节 "Git 基础 - 获取 Git 仓库".
[2] GitHub Docs. *Cloning a repository*. [https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
---
---
## 1.1.3 分支操作
## 1.1.3 分支操作
#### 什么是分支?
#### 什么是分支?
...
@@ -1190,7 +1245,7 @@ hint: 'git pull ...') before pushing again.
...
@@ -1190,7 +1245,7 @@ hint: 'git pull ...') before pushing again.
第一次推送:本地 feature/login ─────→ origin/feature/login
第一次推送:本地 feature/login ─────→ origin/feature/login
│
│
└─ 建立关联(u)
└─ 建立关联(u)
之后:直接 git push 即可,Git 知道推到哪
之后:直接 git push 即可,Git 知道推到哪
```
```
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论