配置git和ssh

查看全局 Git 配置

git config --global --list

#output
user.name=fuck
user.email=scpr7@outlook.com
eval "$(ssh-agent)"

ssh-add -l

ssh-add ~/.ssh/id_ed25519_github

设置当前仓库的 email 和 name

git config --local user.name "Unconnectable"
git config --local user.email "scpr7@outlook.com"

设置全局仓库的 email 和 name

git config --global user.name "Unconnectable"
git config --global user.email "scpr7@outlook.com"

配置你的 ssh

列出 .ssh 目录下的文件

ls -l ~/.ssh
··

列出当前 ssh config

cat ~/.ssh/config

Host github.com
    User git
    IdentityFile ~/.ssh/id_xxxx_github

两个生成 ssh 的算法

ed25519生成 ssh

ssh-keygen -t ed25519 -C "scpr7@outlook.com"

然后会询问你保存路径和密码

Enter file in which to save the key (/home/username/.ssh/id_ed25519): /home/username/.
可以改为ssh/id_ed25519_suffix
你可以加后缀或者更改名字使得更容易辨别

让你输入密码

Enter passphrase (empty for no passphrase):`
Enter same passphrase again:`

RSA生成 ssh

ssh-keygen -t rsa -b 4096 -C "scpr7@outlook.com"

输出你的 pub 复制到 github

cat ~/.ssh/id_ed25519.pub
cat ~/.ssh/id_rsa.pub

修改当前的仓库从http为为ssh,有的时候ssh拉不下来会选择http或者他的镜像,但是到push的时候还是ssh方便

git remore -v #显示当前的remote
git remote set-url origin git@github.com:Unconnectable/xxxxxx

git rebase的使用

想要合并多个commit为一个

git log -oneline #把 log 输出为一行

#查看log历史后使用rebase变基
filament@7945hx:~/Courses/2025s-rcore-Unconnectable$ git log --oneline
440d30a (HEAD -> ch4, origin/ch4) 完成ch4
7ce602c 修改reports
aef5b0d 测试ch4正确程度
f0df504 还差unmap1的测试
3bc5156 未完成
0b7c8e5 继续ch4
12c1e3d 还差map测试
1672914 测试ch4
ab507ee finish sys_trace
073b2ef 添加了reports
eed20af 注释代码
dbd3002 添加注释
4d98714 增加了很多注释
4014758 [chore] remove continue-on-error to confirm correctness
18b6e57 Initialize ch4

#比如需要保留 Initialize ch4 和[chore] remove continue-on-error to confirm correctness 
#把剩下的合并为一个commit

git rebase -i 4014758^
#进入todo页面

修改为以下代码

pick 4014758:保留[chore]commit 不变。

pick 4d98714:作为合并的基础 commit。

squash dbd3002squash 440d30a:将后续 12 个 commit 合并到 4d98714,形成一个新 commit。

pick 4014758 [chore] remove continue-on-error to confirm correctness
pick 4d98714 增加了很多注释
squash dbd3002 添加注释
squash eed20af 注释代码
squash 073b2ef 添加了reports
squash ab507ee finish sys_trace
squash 1672914 测试ch4
squash 12c1e3d 还差map测试
squash 0b7c8e5 继续ch4
squash 3bc5156 未完成
squash f0df504 还差unmap1的测试
squash aef5b0d 测试ch4正确程度
squash 7ce602c 修改reports
squash 440d30a 完成ch4

接下来需要编辑新的commit消息

完成 ch4 开发、测试及文档,包括 sys_trace 和实验报告

然后验证git log --oneline

输出为

9fba672 (HEAD -> ch4) 完成 ch4的作业 rebase之前的commit 还差实验报告
4014758 [chore] remove continue-on-error to confirm correctness
18b6e57 Initialize ch4

完成rebase后需要强制推送

git push --force
posted @ 2025-03-19 20:25  phrink  阅读(31)  评论(0)    收藏  举报