程序员必备技能之 Git

常用命令

拉取代码

1
git clone xxx.git

创建分支

1
2
3
4
5
git branch dev
# or
git checkout -b dev
# or
git switch -c dev

切换本地分支

1
2
3
git checkout dev
# or
git switch dev

切换分支并关联远程分支

1
2
3
git checkout -b dev origin/dev
# or
git checkout --track origin/dev

查看本地所有分支

1
git branch

查看远程所有分支

1
git branch -r

删除本地分支

1
git branch -d dev

删除远程分支

1
git push origin -d dev

将代码从工作区添加暂存区

1
git add .

查看尚未暂存的更新

1
git diff

添加提交信息(commit 注释写错,执行 git commit --amend 此时会进入默认 vim 编辑器,修改注释后保存)

1
git commit -m 'xxxx'

推送代码到远程分支

1
2
3
4
git push origin dev

# 强制推送(常在 git rebase 或 git reset 后使用)
git push -f origin dev

拉取远程分支代码

1
git pull origin dev

合并分支

1
git merge dev

查看 git 状态

1
git status

查看提交历史

1
git log

查看可引用的历史版本记录

1
git reflog

把本地未 push 的分叉提交历史整理成直线

1
git rebase origin/dev

回到 rebase 执行之前的状态

1
git rebase --abort

回退版本

1
2
3
4
5
6
7
# 回退指定 commit_id 版本
git reset --hard commit_id

# 回退上一个版本
git reset --soft HEAD^
# or
git reset --soft HEAD~1

撤销代码

1
git revert commit_id

修改分支名

1
2
3
4
5
6
7
8
# 第一步
git branch -m oldBranchName newBranchName

# 第二步
git push origin :oldBranchName

# 第三步
git push --set-upstream origin newBranchName

查看 git 配置

1
2
3
4
5
# 查看全局配置
git config --global --list

# 查看用户名
git config --global user.name

添加用户名

1
git config --global --add user.name newName

删除用户名

1
git config --global --unset user.name

修改用户名

1
git config --global user.name newName

配置 Git 用户名和邮箱

1
2
3
4
5
# 用户名
git config --global user.name "Your Name"

# 邮箱
git config --global user.email "email@example.com"

统计代码行数

1
git ls-files | xargs wc -l

提交规范

相关参考

feat: 增加新功能
fix: 修复问题/BUG
style: 代码风格相关无影响运行结果的
perf: 优化/性能提升
refactor: 重构
revert: 撤销修改
test: 测试相关
docs: 文档/注释
chore: 依赖更新/脚手架配置修改等
workflow: 工作流改进
ci: 持续集成
types: 类型定义文件更改
wip: 开发中

CodeReview 常用缩写

PR(Pull Request)拉取请求,给其他项目提交代码
LGTM(Looks Good To Me)代码已经过 review,可以合并
SGTM(Sounds Good To Me)和上面那句意思差不多,也是已经通过了 review 的意思
WIP(Work In Progress)如果有个改动很大的 PR,可以在写了一部分的情况下先提交,但需在标题写上 WIP,以告诉项目维护者这个功能还未完成,方便维护者提前 review 部分提交的代码
PTAL(Please Take A Look)提示别人来看一下
TBR(To Be Reviewed)提示维护者进行 review
TL;DR(Too Long; Didn’t Read)太长懒得看
TBD(To Be Done(or Defined/Discussed/Decided/Determined)) 一般表示还没搞定

简单易懂的 Git

Markdown扩展语法学习

1
2
3
4

Markdown 是可以通过 [`markdown-it-py`](https://markdown-it-py.readthedocs.io/en/latest/index.html) 来扩展语法。因为本项目的 Markdown 解析器是 MyST-NB (依赖 MyST ),相关的 Markdown 语法扩展的添加可以前往 {ref}`可选的 MyST 扩展语法 <myst-opational-syntax>` 查看。

下文中 {ref}`定义清单 <markdown-deflist-syntax>` 和 {ref}`任务清单 <markdown-tasklist-syntax>` 以及 {ref}`自动识别网址链接 <markdown-url-syntax>` 都是通过 {ref}`可选的 MyST 扩展语法 <myst-opational-syntax>` 实现的。

表格

要添加表,请使用三个或多个连字符(---)创建每列的标题,并使用管道(|)分隔每列。您可以选择在表的任一端添加管道。

1
2
3
4
| Syntax    | Description |
| --------- | ----------- |
| Header | Title |
| Paragraph | Text |

呈现的输出如下所示:

Syntax Description
Header Title
Paragraph Text

提示: 使用连字符和管道创建表可能很麻烦。为了加快这一过程,请尝试使用Markdown Tables Generator。使用图形界面构建表,然后将生成的Markdown格式的文本复制到文件中。当然也可以直接使用 Typora 编辑器,该编辑提供了表格的快速创建和编辑功能。

格式化表格中的文字

您可以格式化表格中的文本。例如,您可以添加链接代码(```仅在刻度线()中显示单词或短语,而不能在代码块中添加)和强调

您不能添加标题,块引用,列表,水平规则,图像或HTML标签。


围栏代码块

1
由于此电子书是基于 MyST Parser 来解析的,所以其代码高亮是适用 pygments 实现的; [点击查看关于代码高亮 pygments 支持的语言](https://pygments.org/languages/)。

Markdown基本语法允许您通过将行缩进四个空格或一个制表符来创建代码块。如果发现不方便,请尝试使用受保护的代码块。根据Markdown处理器或编辑器的不同,您将在代码块之前和之后的行上使用三个刻度线(```)或三个波浪号(~~~)。如果想要包含一个含有三个刻度线(```),可以使用四个刻度:

:::markdown

```

:::

1
2
3
4
5
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}

呈现的输出如下所示:

:::{card}

1
2
3
4
5
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}

:::

语法高亮

许多Markdown处理器都支持围栏代码块的语法突出显示。此功能使您可以为代码编写时使用的任何语言添加颜色突出显示。要添加语法突出显示,请在受防护的代码块之前的对号旁指定一种语言。

1
2
3
4
5
6
7
```json
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
```

呈现的输出如下所示:

:::{card}

1
2
3
4
5
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}

:::

脚注

脚注使您可以添加注释和参考,而不会使文档正文混乱。创建脚注时,带有脚注引用的链接将出现带有链接的上标编号。读者可以单击链接跳至页面底部的脚注内容。

要创建脚注参考,请在方括号([^1])内添加插入符号和标识符。标识符可以是数字或文字,但他们不能包含空格或制表符。标识符仅将脚注参考与脚注本身相关联-在输出中,脚注按顺序编号。

在括号内使用另一个插入符号和数字添加脚注,并用冒号和文本([^1]: My footnote.)括起来。您不必在文档末尾添加脚注。你可以把他们的任何地方,除了像列表一样,块报价,和表格等元素里面。

1
2
3
4
5
6
7
8
9
10
11
Here's a simple footnote,[^1] and here's a longer one.[^bignote]

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

Indent paragraphs to include them in the footnote.

`{ my code }`

Add as many paragraphs as you like.

呈现的输出如下所示:

Here’s a simple footnote,[^1] and here’s a longer one.[^bignote]


(markdown-deflist-syntax)=

定义清单

一些Markdown处理器允许您创建自定义列表和术语及其相应的定义。要创建定义列表,请在第一行上键入术语。下一行,键入一个冒号后跟一个空格和定义。

1
2
3
4
5
6
First Term
: This is the definition of the first term.

Second Term
: This is one definition of the second term.
: This is another definition of the second term.

运行效果:

:::{card}

First Term
This is the definition of the first term.
Second Term
: This is one definition of the second term.
This is another definition of the second term.

:::

删除线

您可以通过在单词中心放置一条水平线来“删除”单词。结果看起来像这样。此功能使您可以指示某些单词是一个错误,并不表示要包含在文档中。若要删除单词,请~~在单词前后使用两个波浪号()。

1
~~The world is flat.~~ We now know that the world is round.

呈现的输出如下所示:

The world is flat. We now know that the world is round.


(markdown-tasklist-syntax)=

任务清单

任务列表使您可以创建带有复选框的项目列表。在支持任务列表的Markdown应用程序中,复选框将显示在内容旁边。要创建任务列表,请在任务列表项之前添加破折号(-)和方括号,并[ ]在其前面加上一个空格()。要选择一个复选框,请x在方括号([x])之间添加in 。

1
2
3
- [x] Write the press release
- [ ] Update the website
- [ ] Contact the media

呈现的输出如下所示:

:::{card}

  • Write the press release
  • Update the website
  • Contact the media

:::

(markdown-url-syntax)=

自动识别网址链接

许多Markdown处理器会自动将URL转换为链接。这意味着如果您输入http://www.example.com,即使您没有[使用方括号](http://markdown.p2hp.com/basic-syntax/index.html#links),您的Markdown处理器也会自动将其转换为链接。

这个功能需要使用到 Markdown 的扩展 linkify-it-py。要么直接 pip install linkify-it-py 或通过 pip install myst-parser[linkify] 安装 Python 模块。 相关笔记可前往笔记—— {ref}可选的 MyST 扩展语法中的链接扩展语法的开启和使用 <markdown-ext-syntax-linkify>

1
http://www.example.com

呈现的输出如下所示:

http://www.example.com

禁用自动URL链接

如果您不希望自动链接URL,则可以通过将URL表示为带有刻度线的代码来删除该链接。

1
`http://www.example.com`

呈现的输出如下所示:

http://www.example.com

[^1]: This is the first footnote.

[^bignote]: Here’s one with multiple paragraphs and code.

Indent paragraphs to include them in the footnote.

`{ my code }`

Add as many paragraphs as you like.

Markdown基础语法学习 (1)

标题

要创建标题,请在单词或短语的前面添加一定数量的 # 符号。(符号数量在1~6,一般来说4级标题足以应对)

Markdown HTML
# Heading level 1 <h1>Heading level 1</h1>
## Heading level 2 <h2>Heading level 2</h2>
### Heading level 3 <h3>Heading level 3</h3>
#### Heading level 4 <h4>Heading level 4</h4>
##### Heading level 5 <h5>Heading level 5</h5>
###### Heading level 6 <h6>Heading level 6</h6>

段落

要创建段落,请使用空白行分隔一行或多行文本。您不应缩进带有空格或制表符的段落。

1
2
3
我真的很喜欢使用Markdown。

我想从现在开始,我将使用它来格式化所有文档。

下方为段落示例代码的渲染输出

我真的很喜欢使用Markdown。

我想从现在开始,我将使用它来格式化所有文档。

换行

要创建换行符(<br>),请以 两个或多个空格结束一行,然后键入return

1
2
This is the first line.
And this is the second line.

下方为换行示例代码的渲染输出

This is the first line.
And this is the second line.

字体

要加粗文本,请在单词或短语的前后添加两个星号或下划线。要加粗一个单词的中部以强调,请在字母周围添加两个星号,且各空格之间不加空格。Markdown 可以使用以下几种字体:

1
2
3
4
5
6
*斜体文本*
_斜体文本_
**粗体文本**
__粗体文本__
***粗斜体文本***
___粗斜体文本___

下方为字体示例代码的渲染输出

斜体文本
斜体文本
粗体文本
粗体文本
粗斜体文本
粗斜体文本

块引用

要创建 blockquote,请>在段落前面添加一个。

1
> Dorothy followed her through many of the beautiful rooms in her castle.

呈现的输出如下所示:

Dorothy followed her through many of the beautiful rooms in her castle.

多个段落块引用

块引用可以包含多个段落。段落之间的空白行上添加一个 >

1
2
3
> Dorothy followed her through many of the beautiful rooms in her castle.
>
> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

呈现的输出如下所示:

Dorothy followed her through many of the beautiful rooms in her castle.

The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

嵌套块引用

块引用可以嵌套。>>在要嵌套的段落前面添加一个。

1
2
3
> Dorothy followed her through many of the beautiful rooms in her castle.
>
>> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

呈现的输出如下所示:

Dorothy followed her through many of the beautiful rooms in her castle.

The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

具有其他元素的块引用

块引用可以包含其他Markdown格式的元素。并非所有元素都可以使用-您需要进行实验以查看哪些元素有效。

1
2
3
4
5
6
> #### The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
> *Everything* is going according to **plan**.

呈现的输出如下所示:

季度业绩看起来不错!

  • 收入超出了预期。
  • 利润比以往任何时候都高。

一切都按计划进行

有序列表

要创建有序列表,请在订单项中添加数字和句点。数字不必按数字顺序排列,但列表应以数字开头。

1
2
3
4
5
6
7
8
9
10
1. First item
8. Second item
3. Third item
5. Fourth item
1. First item
2. Second item
3. Third item
1. Indented item
2. Indented item
4. Fourth item

上方有序列表呈现的输出如下所示

  1. First item
  2. Second item
  3. Third item
  4. Fourth item
  5. First item
  6. Second item
  7. Third item
    1. Indented item
    2. Indented item
  8. Fourth item

无序列表

要创建无序列表,请在订单项前添加破折号(-),星号(*)或加号(+)。缩进一个或多个项目以创建嵌套列表。

1
2
3
4
5
6
* First item
* Second item
* Third item
* Indented item
* Indented item
* Fourth item

上方无序列表呈现的输出如下所示

  • First item
  • Second item
  • Third item
    • Indented item
    • Indented item
  • Fourth item

在列表中添加元素

要在保留列表连续性的同时在列表中添加另一个元素,请将该元素缩进四个空格或一个制表符,如以下示例所示。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
* This is the first list item.

> A blockquote would look great below the second list item.

* Here's the second list item.

I need to add another paragraph below the second list item.

* And here's the third list item.

<head>
<title>Test</title>
</head>

* And here's the fourth list item.

![tux.png](./example/tux.png)

* And here's the fifth list item.

呈现的输出如下所示:

  • This is the first list item.

    A blockquote would look great below the second list item.

  • Here’s the second list item.

    I need to add another paragraph below the second list item.

  • And here’s the third list item.

    1
    2
    3
    <head>
    <title>Test</title>
    </head>
  • And here’s the fourth list item.

    tux.png

  • And here’s the fifth list item.

代码

要将单词或短语表示为代码,请将其括在勾号(```)中。

1
At the command prompt, type `nano`.

呈现的输出如下所示:

At the command prompt, type nano.

转义刻度线

如果要表示为代码的单词或短语包含一个或多个刻度线,可以通过将单词或短语括在双刻度线(````)中来对其进行转义。

1
``Use `code` in your Markdown file.``

呈现的输出如下所示:

Use `code` in your Markdown file.

代码块

要创建代码块,请在代码块的每一行缩进至少四个空格或一个制表符。

1
2
3
<head>
<title>Test</title>
</head>

呈现的输出如下所示:

<head>
    <title>Test</title>
</head>

扩展语法中有代码块的扩展语法 围栏代码块。

链接

要创建链接,请将链接文本括在方括号(例如[Duck Duck Go])中,然后立即在URL后面加上括号(例如(https://duckduckgo.com))中的URL 。

1
My favorite search engine is [Duck Duck Go](https://duckduckgo.com).

呈现的输出如下所示:

My favorite search engine is Duck Duck Go.

添加标题

您可以选择为链接添加标题。当用户将鼠标悬停在链接上时,这将显示为工具提示。要添加标题,请将其括在URL后面的括号中。

1
My favorite search engine is [Duck Duck Go](https://duckduckgo.com "The best search engine for privacy").

呈现的输出如下所示:

My favorite search engine is Duck Duck Go.

网址和电子邮件地址

要将URL或电子邮件地址快速转换为链接,请将其括在尖括号中。

1
2
3
<https://markdown.p2hp.com>

<fake@example.com>

呈现的输出如下所示:

https://markdown.p2hp.com

fake@example.com

格式化链接

为了强调链接,请在方括号和括号之前和之后添加星号。

1
2
3
I love supporting the **[EFF](https://eff.org)**.

This is the *[Markdown Guide](https://markdown.p2hp.com)*.

呈现的输出如下所示:

I love supporting the EFF.

This is the Markdown Guide.

引用样式链接

引用样式链接是一种特殊的链接,它使URL在Markdown中更易于显示和阅读。引用样式的链接分为两部分:与文本保持内联的部分以及在文件中其他位置存储的部分,以使文本易于阅读。

1
2
3
4
5
In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends
of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
eat: it was a [hobbit-hole][1], and that means comfort.

[1]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> "Hobbit lifestyles"

呈现的输出如下所示:

In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort.


图片

要添加图像,请添加感叹号(!),然后在括号中添加替代文本,并在括号中添加图像资源的路径或URL。您可以选择在括号中的URL之后添加标题。

注意: 使用Markdown并不意味着您也不能使用HTML。可以将HTML标签添加到任何Markdown文件中。如果您更喜欢某些HTML标记而不是Markdown语法,这将很有帮助。例如,将HTML标签用于图像更容易调整图片。当然,我们需要添加 markdown-it-py 扩展配置,配置方法参考 {ref}可选的 MyST 扩展语法 <myst-opational-syntax> 的 {ref}MyST 提供的几种不同的语法来在文档中包含图像 <myst-optional-syntax-img>

1
2
3
![tux.png](./example/tux.png)

<img src="./example/tux.png" alt="tux.png" style="zoom:33%;" />

tux.png

tux.png

水平线

要创建水平线***,请单独在一行上使用三个或更多的星号(),破折号(---)或下划线(___


转义字符

要显示原义字符,否则将用于设置Markdown文档中的文本格式\,请在字符前面添加反斜杠()。

1
\* Without the backslash, this would be a bullet in an unordered list.

呈现的输出如下所示:

* 如果没有反斜杠,这将是无序列表中的项目符号。

可以使用反斜杠转义以下字符

字符 名称
\ 反斜杠
` 刻度线(另请参见转义刻度线中的代码
* 星号
_ 下划线
{} 大括号
[] 中括号
() 括号
# 井号
+ 加号
- 减号(连字符)
.
! 感叹号
| 管道(另请参见表中的转义管道

总览

Markdown 速查表提供了所有 Markdown 语法元素的基本解释。如果你想了解某些语法元素的更多信息,请参阅更详细的 基本语法扩展语法.

# 基本语法

这些是 John Gruber 的原始设计文档中列出的元素。所有 Markdown 应用程序都支持这些元素。

元素 Markdown 语法
标题(Heading) # H1
## H2
### H3
粗体(Bold) **bold text**
斜体(Italic) *italicized text*
引用块(Blockquote) > blockquote
有序列表(Ordered List) 1. First item
2. Second item
3. Third item
无序列表(Unordered List) - First item
- Second item
- Third item
代码(Code) code
分隔线(Horizontal Rule) ---
链接(Link) [title](https://www.example.com)
图片(Image) ![alt text](image.jpg)

# 扩展语法

这些元素通过添加额外的功能扩展了基本语法。但是,并非所有 Markdown 应用程序都支持这些元素。

元素 Markdown 语法
表格(Table) -
代码块(Fenced Code Block) ``` ```
脚注(Footnote) Here’s a sentence with a footnote. [^1]
[^1]: This is the footnote.
标题编号(Heading ID) `### My Great Heading

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout…
“Oh My ZSH!”

Quick Start

Install oh-my-zsh now

Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either curl or wget.

1
2
3
4
5
# Install oh-my-zsh via curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Install oh-my-zsh via wget
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

Not ready to jump right in? We’re not offended; it’s never a bad idea to read the documentation first.

Psst… Oh My Zsh works best on macOS or Linux.

THEME

1
brew install romkatv/powerlevel10k/powerlevel10k

More info: powerlevel10k

PLUGINS

  • autojump
  • zsh-syntax-highlighting
1
2
3
4
5
6
7
8
9
10
brew install autojump

# 补全提示
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# 高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 国内镜像
git clone https://gitee.com/han8gui/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://gitee.com/Annihilater/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

upgrade

1
upgrade_oh_my_zsh

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

0%