注意到之前我复刻的是master分支,但是没有dev分支
这就很难受,提交了之后却看不到,还得跑到原项目里查看
所以我就把复刻的仓库加上dev分支
这里记一下执行顺序吧,总是搞错顺序产生冲突
创建fork的dev分支步骤
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| git clone https://github.com/huyangpahuo/hexo-theme-magzine.git cd hexo-theme-magzine
git remote set-url origin git@github-huyang-01:huyangpahuo/hexo-theme-magzine.git
git remote add upstream git@github-huyang-01:forever218/hexo-theme-magzine.git
git remote -v
git fetch upstream
git switch -c dev --track upstream/dev
git push -u origin dev
|
于是分为两种上传方式
第一:只同步和维护我自己 fork 的 `dev`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| git switch dev
git fetch upstream git merge upstream/dev
git status
git diff
git add .
git diff --cached
git commit -m "更新说明"
git push
|
第二:PR给原作者的 `dev`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| git switch dev
git fetch upstream git merge upstream/dev
git switch -c 你的新分支名
git status git diff
git add .
git diff --cached
git commit -m "更新说明"
git push -u origin 你的新分支名
|
然后涉及到的Git命令如下
| 功能 |
命令(新 Git 写法) |
命令(旧 Git 写法) |
说明 |
| 克隆仓库 |
git clone <仓库地址> |
同上 |
克隆远程仓库到本地 |
| 进入项目 |
cd <项目文件夹> |
同上 |
进入本地仓库 |
| 查看远程 |
git remote -v |
同上 |
查看 origin/upstream 等远程地址 |
| 添加上游 |
git remote add upstream <地址> |
同上 |
第一次配置原作者仓库,地址是HTTPS或SSH |
| 修改远程地址 |
git remote set-url <name> <地址> |
同上 |
改 SSH/HTTPS,或更新远程地址,name一般为origin/upstream |
| 切换到已有分支 |
git switch dev |
git checkout dev |
切换本地已有分支 |
| 创建并切换新分支 |
git switch -c 分支名 |
git checkout -b 分支名 |
基于当前分支创建新分支并切换过去 |
| 查看当前状态 |
git status |
同上 |
查看修改、暂存和分支状态 |
| 查看改动内容 |
git diff |
同上 |
查看未暂存的改动 |
| 查看暂存区改动 |
git diff --cached |
同上 |
查看已 add 但未提交的内容 |
| 暂存改动 |
git add . |
同上 |
把所有改动加入暂存区 |
| 提交改动 |
git commit -m "说明" |
同上 |
提交到本地仓库 |
| 拉取远程分支信息 |
git fetch upstream |
同上 |
获取上游分支更新,不合并 |
| 合并远程分支到本地 |
git merge upstream/dev |
同上 |
把上游 dev 合并到本地分支 |
| 推送到远程 |
git push -u origin 分支名 |
同上 |
-u 建立跟踪关系,可选;首次推送新分支建议加 |
| 推送已有分支 |
git push |
同上 |
如果分支已和远程跟踪,直接推送即可 |
| 查看分支列表 |
git branch |
同上 |
查看本地所有分支,* 表示当前分支 |
| 查看分支和远程跟踪关系 |
git branch -vv |
同上 |
显示本地分支和对应远程分支、最后提交 |
| 查看远程分支 |
git branch -r |
同上 |
显示远程分支列表 |
| 查看本地 + 远程分支 |
git branch -a |
同上 |
显示所有分支 |
| 删除分支 |
git branch -d <分支> / git push origin --delete <分支> |
同上 |
清理完成的分支 |
这里有几个注意点
git remote set-url < name > <地址>
例如git remote add upstream git@github-huyang-01:forever218/hexo-theme-magzine.git
<name> 就是你远程仓库的“别名”,不是随便写的名字
- Git 默认有一个远程仓库叫
origin,你 fork 的仓库通常就是 origin
- 你加上原作者仓库一般叫
upstream,当然也有自定义的名字
git push -u origin 分支名
-u 等同于 --set-upstream,用于建立本地分支和远程分支的跟踪关系
示例:
1
| git push -u origin fix-imagezoom
|
- 这里的意思是:
- 把本地
fix-imagezoom 分支推到 origin 上
- 同时告诉 Git:以后本地
fix-imagezoom 默认跟踪远程 origin/fix-imagezoom
- 后续再推送或拉取时,只需要:
Git 会自动知道你想推/拉 origin/fix-imagezoom。
如果不加 -u:
1 2
| git push origin fix-imagezoom git pull origin fix-imagezoom
|
因为合并之后我都是统统删光,所以再搞一次我又不会了 ┭┮﹏┭┮,然后又问AI,太低效了
所以这次分为4种情况,不会了我再看两眼
1️⃣ 只同步和维护自己 fork 的 dev
情况 A:本地和远程都没有同步(第一次更新或本地删除过)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| git clone git@github-huyang-01:huyangpahuo/hexo-theme-magzine.git cd hexo-theme-magzine
git remote add upstream git@github-huyang-01:forever218/hexo-theme-magzine.git
git remote -v
git switch -c dev --track upstream/dev
git push -u origin dev
git status git diff
git add .
git diff --cached
git commit -m "更新说明"
git push
|
情况 B:本地 dev 已经存在,远程 fork dev 已同步(继续维护)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| git clone git@github-huyang-01:huyangpahuo/hexo-theme-magzine.git cd hexo-theme-magzine
git remote add upstream git@github-huyang-01:forever218/hexo-theme-magzine.git
git remote -v
git switch dev
git fetch upstream git merge upstream/dev
git status git diff
git add . git diff --cached git commit -m "更新说明"
git push
|
✅ 这种情况只更新你自己的 fork,不发 PR。
2️⃣ 给作者发 PR 的流程
情况 A:本地和远程都没有同步(第一次做 PR)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| git clone git@github-huyang-01:huyangpahuo/hexo-theme-magzine.git cd hexo-theme-magzine
git remote add upstream git@github-huyang-01:forever218/hexo-theme-magzine.git
git remote -v
git switch -c dev --track upstream/dev
git fetch upstream git merge upstream/dev git push -u origin dev
git switch -c 你的新分支名
git status git diff
git add . git diff --cached git commit -m "更新说明"
git push -u origin 你的新分支名
|
情况 B:本地 dev 已存在,远程 fork dev 已同步(继续做 PR)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| git clone git@github-huyang-01:huyangpahuo/hexo-theme-magzine.git cd hexo-theme-magzine
git remote add upstream git@github-huyang-01:forever218/hexo-theme-magzine.git
git remote -v
git switch dev
git fetch upstream git merge upstream/dev
git switch -c 你的新分支名
git status git diff
git add . git diff --cached git commit -m "更新说明"
git push -u origin 你的新分支名
git switch dev git branch -d 你的新分支名 git push origin --delete 你的新分支名
|
嘶,突然意识到github不就是一个高级版本的网盘吗真的是,反正我最讨厌的就是百度网盘和迅雷网盘,下载的速度简直就是蛆
夸克网盘和阿里网盘还好一点,至少不需要看广告加速,蓝奏云网盘和Google Drive感觉最好下载快还没广告
评论区