This commit is contained in:
128
Git/GIt的使用.md
Normal file
128
Git/GIt的使用.md
Normal file
@@ -0,0 +1,128 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 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)
|
||||
|
||||
## 基础命令
|
||||
|
||||
- 新建分支
|
||||
|
||||
```bash
|
||||
git branch demo
|
||||
```
|
||||
|
||||
- 切换分支
|
||||
|
||||
```bash
|
||||
git checkout demo
|
||||
```
|
||||
|
||||
- 新建并切换到新分支
|
||||
|
||||
```bash
|
||||
git checkout -b demo
|
||||
```
|
||||
|
||||
- 合并分支
|
||||
|
||||
```bash
|
||||
git merge hotfix
|
||||
```
|
||||
|
||||
- 删除分支
|
||||
|
||||
```bash
|
||||
git branch -d hotfix
|
||||
```
|
||||
|
||||
- 查看状态
|
||||
|
||||
```bash
|
||||
git status
|
||||
```
|
||||
|
||||
- 启动一个合适的可视化合并工具
|
||||
|
||||
```bash
|
||||
git mergetool
|
||||
```
|
||||
|
||||
- 添加仓库
|
||||
|
||||
```bash
|
||||
git remote add origins Git地址
|
||||
```
|
||||
|
||||
- 拉取代码
|
||||
|
||||
```bash
|
||||
git pull origins
|
||||
```
|
||||
|
||||
- 查看提交信息
|
||||
|
||||
```bash
|
||||
git log
|
||||
```
|
||||
|
||||
- 回滚代码
|
||||
|
||||
```bash
|
||||
git reset --hard ID信息
|
||||
```
|
||||
|
||||
- 不回滚已修改的代码
|
||||
|
||||
```bash
|
||||
git reset ID信息
|
||||
```
|
||||
|
||||
- 清楚缓存
|
||||
|
||||
```bash
|
||||
git credential-cache exit
|
||||
```
|
||||
|
||||
## 跨分支合并某个提交记录
|
||||
|
||||
> 例子:假如我有 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
|
||||
```
|
||||
|
||||
|
34
Git/Git免密拉取代码.md
Normal file
34
Git/Git免密拉取代码.md
Normal file
@@ -0,0 +1,34 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Git免密拉取代码
|
||||
|
||||
## 第一种
|
||||
|
||||
1. 生成密钥
|
||||
|
||||
```bash
|
||||
ssh-keygen
|
||||
```
|
||||
|
||||
2. 查看密钥
|
||||
|
||||
```bash
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
```
|
||||
|
||||
2. 到代码仓库配置 SSH 密钥直接 git clone 免密拉取
|
||||
|
||||
|
||||
|
||||
## 第二种
|
||||
|
||||
在命令里使用账号密码或令牌拉取
|
||||
|
||||
```bash
|
||||
git clone -b main --depth=1 https://$GIT_USERNAME:$GIT_PASSWORD@github.com/offends/demo.git
|
||||
```
|
||||
|
||||
```bash
|
||||
git clone -b main --depth=1 https://$GIT_TOKEN@github.com/offends/demo.git
|
||||
```
|
||||
|
42
Git/Git清除提交记录.md
Normal file
42
Git/Git清除提交记录.md
Normal file
@@ -0,0 +1,42 @@
|
||||
> 作者:丁辉
|
||||
|
||||
# 清除GitHub中的所有提交历史记录
|
||||
|
||||
1. 创建了一个新的分支
|
||||
|
||||
```bash
|
||||
git checkout --orphan latest_branch
|
||||
```
|
||||
|
||||
2. 添加所有文件
|
||||
|
||||
```bash
|
||||
git add -A
|
||||
```
|
||||
|
||||
3. 提交更改
|
||||
|
||||
```bash
|
||||
git commit -am "commit message"
|
||||
```
|
||||
|
||||
4. 删除分支
|
||||
|
||||
```bash
|
||||
git branch -D main
|
||||
```
|
||||
|
||||
5. 将当前分支重命名
|
||||
|
||||
```bash
|
||||
git branch -m main
|
||||
```
|
||||
|
||||
6. 最后,强制更新存储库
|
||||
|
||||
```bash
|
||||
git push -f origin main
|
||||
```
|
||||
|
||||
|
||||
|
30
Git/Git配置本地代理.md
Normal file
30
Git/Git配置本地代理.md
Normal file
@@ -0,0 +1,30 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Git配置本地代理
|
||||
|
||||
> 本地启动代理后,使用命令更改端口
|
||||
|
||||
```bash
|
||||
# socks5协议,1080端口修改成自己的本地代理端口
|
||||
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
|
||||
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
|
||||
|
||||
# http协议,1081端口修改成自己的本地代理端口
|
||||
git config --global http.https://github.com.proxy https://127.0.0.1:1081
|
||||
git config --global https.https://github.com.proxy https://127.0.0.1:1081
|
||||
```
|
||||
|
||||
- 查看所有配置
|
||||
|
||||
```bash
|
||||
git config -l
|
||||
```
|
||||
|
||||
- 取消 reset 代理设置
|
||||
|
||||
```bash
|
||||
git config --global --unset http.proxy
|
||||
git config --global --unset https.proxy
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user