一、Git
1. 集中式 vs 分布式


2. 初始化配置
git config --global user.name "username"
git config --global user.email "user-email"
3. 创建版本库
git init
git add readme.txt
git commit -m "create readme.txt file"
4. 查看状态
git status
git diff
5. 版本回退
git log
git log --pretty=oneline
git reset --hard HEAD^
git reflog
6. 工作区与暂存区
7. 管理修改
// 查看工作区中的文件与版本库中最新版本的区别
git diff HEAD -- readme.txt
8. 撤销修改
git restore readme.txt
git restore --staged readme.txt
9. 删除文件
git rm test.txt
git commit
10. 远程仓库
ssh-keygen -t rsa -C "springbear2020@163.com"
git remote add origin https://gitee.com/Spring-_-Bear/temp.git
git push -u origin master
git push origin master
git remoter -v
git remote rm origin
git clone git@gitee.com:Spring-_-Bear/temp.git
11. 分支管理





12. 创建与合并分支
git switch -c dev
git branch
git switch master
git merge dev
git branch -d dev
13. 解决冲突
git log --graph --pretty=oneline --abbrev-commit
14. 分支管理策略
git merge --no-ff -m "merge with no-ff" dev


15. Bug 分支
git stash
git stash list
git stash pop
git stash apply stash@{0}
git stash drop stash@{0}
git cherry-pick 9863d08
16. Feature 分支
git branch -D feature
17. 多人协作
git switch -c dev origin/dev
git branch --set-upstream-to=origin/dev dev
git pull
18. Rebase
19. 标签管理
git tag tag_name commit_id
git tag
git show tag_name
git tag -a tag_name -m "tag_describtion" commit_id
git tag -d tag_name
git push origin tag_name
git push origin --tags
git tag -d tag_name
git push origin :refs/tags/tag_name
20. 自定义 Git
git config --global color.ui true
21. 忽略特殊文件
git add -f filename
22. 命令别名
git config --global alias.st status
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
23. 搭建 Git 服务器
sudo apt-get install git
sudo adduser git
/home/git/.ssh/authorized_keys
sudo git init --bare sample.git
sudo chown -R git:git sample.git
git:x:1001:1001:,,,:/home/git:/bin/bash
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
24. 命令总结
序号 | 命令 | 功能 |
---|
1 | git config --global user.name <name> | 配置全局用户名。省略 --global 参数则配置的当前 repo 的用户名 |
2 | git config --global user.email <email> | 配置全局用户邮箱。省略 --global 参数则配置的当前 repo 的邮箱 |
3 | git config --global --edit | 打开当前用户的 git 全局配置并编辑 |
4 | git config --global alias.<alias-name> <git-command> | 配置一个 git 命令的快捷方式 |
5 | git config --system core.editor <editor> | 配置文本编辑器 |
6 | git init <directory> | 在指定目录里下创建一个空的 repo。省略参数则在当前目录创建 |
7 | git add <directory> | 将指定目录的文件加入到暂存区。若参数是文件则将文件添加到暂存区 |
8 | git commint -m “<message>” | 提交暂存区的修改,使用指定的提交信息 |
9 | git commit -m <message> --amend | 将当前 staged 修改合并到最近一次的 commit 中 |
10 | git status | 查看仓库状态 |
11 | git log | 以缺省格式显示全部 commit 历史 |
12 | git log -<limit> | 限制 log 的显示数量 |
13 | git log --oneline | 每行显示一条 commit |
14 | git log --author=“<pattern>” | 按提交者名字搜索并显示 commit |
15 | git log --grep=“<pattern>” | 按指定内容搜索并显示 commit |
16 | git log <since>…<until> | 显示指定范围的 commit。参数可以是 commit id、分支名称、HEAD 或任意相对位置 |
17 | git log – <file> | 仅显示包含指定文件修改的 commit |
18 | git reflog | 显示本地 repo 的所有commit 日志 |
19 | git diff | 比较暂存区和工作区的修改 |
20 | git diff HEAD | 比较工作区和上一次 commit 后的修改 |
21 | git diff --cached | 比较工作区和上一次 commit 后的修改 |
22 | git revert <commit> | 回滚到指定的 commit |
23 | git switch -c <branch> | 创建并切换到一个新分支。省略 -c 参数将切换到指定分支 |
24 | git branch | 显示本地 repo 的所有分支 |
25 | git log --graph | 显示图形化的 branch 信息 |
26 | git merge <branch> | 将指定的分支合并到当前分支 |
27 | git reset <file> | 将 file 从暂存区移除,但保持工作区不变 |
28 | git reset | 移除暂存区的所有修改,但不会影响到工作区 |
29 | git reset --hard | 移除所有暂存区的修改,并强制删除所有工作区的修改 |
30 | git reset <commit> | 将当前分支回滚到指定 commit,清除暂存区的修改,但保持工作区状态不变 |
31 | git reset --hard <commit> | 将当前分支回滚到指定 commit,清除暂存区的修改,并强制删除工作区的修改 |
32 | git remote add <name> <url> | 添加一个新的远程连接。用 <name> 作为远程库的名称 |
33 | git clone <repository> | 克隆一个指定的 repo 到本地,指定的 repo 可以是本地文件系统或者由 http、ssh 指定的远程路径 |
34 | git push <remote> <branch> | 将本地指定分支推送到远程库,若远程库中无此分支则自动创建 |
35 | git push <remote> --force | 将本地分支推送到远程库 |
36 | git push <remote> --tags | 本地所有的 tag 推送到远程库 |
37 | git pull <remote> | 从指定远程库抓取所有分支的 commit 并立刻合并到本地 repo |
38 | git fetch <remote> <branch> | 从指定的远程库抓取指定分支的所有 commit 到本地 repo。省略 <branch> 参数将抓取远程库的所有修改 |
39 | git pull --rebase <reomote> | 抓取远程库所有分支,并以 rebase 模式并入本地 repo 而不是 merge |
40 | git rebase <base> | 基于 <base> 对当前分支进行 rebase,<base> 可以是 commit、分支名称、tag 或相对于 HEAD 的 commit |
41 | git rebase -i <base> | 以交互模式对当前分支做 rebase |
二、SQL
1. 关系型数据库概述



2. 键约束
ALTER TABLE table_name ADD CONSTRAINT uni_name UNIQUE (name);
3. 数据查询




4. MySQL
5. 实用 SQL 语句
REPLACE INTO students (id, class_id, name, gender, score) VALUES (1, 1, '小明', 'F', 99);
INSERT INTO students (id, class_id, name, gender, score) VALUES (1, 1, '小明', 'F', 99) ON DUPLICATE KEY UPDATE name='小明', gender='F', score=99;
INSERT IGNORE INTO students (id, class_id, name, gender, score) VALUES (1, 1, '小明', 'F', 99);
SELECT * FROM students FORCE INDEX (idx_class_id) WHERE class_id = 1 ORDER BY id DESC;
6. 事务
名称 | 描述 |
---|
原子性(atomic) | 将所有 SQL 作为原子工作单元执行,要么全部执行,要么全部不执行 |
一致性(consistency) | 事务操作成功,所有数据的状态都是一致的 |
隔离性(isolation) | 如果有多个事务并发执行,事务之间必须隔离执行 |
持久性(duration) | 事务操作成功,对数据的修改被持久化存储 |
MySQL隔离级别 | 脏读 | 不可重复读 | 幻读 |
---|
读未提交(read uncommintted) | Y | Y | Y |
读已提交(read committed) | N | Y | Y |
可重复读(repeatable read) | N | N | Y |
可串行化(serializable) | N | N | N |