新增Git操作文档
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
2025-12-26 21:01:44 +08:00
parent 09a4112b40
commit ce98d5e641
4 changed files with 138 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
> 本文作者:丁辉
# GIt的使用
# GIt基础命令
[官网](https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA%E4%B8%8E%E5%90%88%E5%B9%B6)

91
Git/GIt多仓库控制.md Normal file
View File

@@ -0,0 +1,91 @@
> 本文作者:丁辉
# GIt多仓库控制
> 你可以通过添加多个远程仓库,然后从一个远程仓库拉取,推送到另一个远程仓库
## 方法一(添加双远程仓库推荐)
1. 克隆第一个仓库
```bash
git clone <仓库地址>
```
2. 查看当前远程(默认是 origin )
```bash
git remote -v
```
3. 添加第二个仓库,作为另一个远程仓库
```bash
git remote add origin2 <第二个仓库地址>
```
4. 再次查看,现在应该有两个远程仓库
```bash
git remote -v
```
5. 从仓库一拉取最新代码
```bash
git pull origin main
```
6. 修改文件并提交
```bash
git add .
git commit -m "修改说明"
```
7. 推送到仓库二
```bash
git push origin2 main
```
8. 推送完成
## 方法二(单向同步修改现有远程地址)
1. 克隆第一个仓库
```bash
git clone <仓库地址>
```
2. 移除原有的 Origin 远程
```bash
git remote remove origin
```
3. 添加新的仓库作为 Origin
```bash
git remote add origin <新的仓库地址>
```
4. 修改文件并提交
```bash
git add .
git commit -m "修改说明"
```
5. 推送到新的仓库地址
```bash
git push origin main
```
## 注意事项
1. **认证问题**:确保你有两个仓库的推送权限
2. **分支一致性**确认两个仓库使用相同的主分支名main 或 master
3. **冲突处理**:如果两个仓库都有更新,可能需要先合并

View File

@@ -0,0 +1,46 @@
> 本文作者:丁辉
# GIt跨分支合并某个提交记录
## 跨分支合并某个提交记录
> 例子:假如我有 A 、B 分支
1. 切换到 A 分支
```bash
git checkout <A分支>
```
2. 查看提交日志拿到值
```bash
git log
```
3. 切换到 B 分支
```bash
git checkout <B分支>
```
4. 合并
```bash
git cherry-pick '获取到的提交记录值'
```
5. 检查提交记录,查看是否将 A 文件合并到了 B 仓库
```bash
git log
```
6. 提交文件
```bash
git add .
git push
```

View File

@@ -18,8 +18,6 @@
2. 到代码仓库配置 SSH 密钥直接 git clone 免密拉取
## 第二种
在命令里使用账号密码或令牌拉取