后浪笔记一零二四

Git 等常用工具配置

Git

用户与鉴权

 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
# 生成SSH公钥对
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

# 配置用户名和邮箱
git config --global user.name <username>
git config --global user.email <email@example.com>

# 针对 https 协议的仓库,记住密码,避免每次都要求输入密码
git config --global credential.helper store

# 自动拉取 submodule
git config --global submodule.recurse true

# false: 处理换行符时不进行任何自动转换
# true: 在提交时将 CRLF 转换为 LF,并在检出时将 LF 转换回 CRLF
# input: 在提交时将 CRLF 转换为 LF,但是在检出时不做任何转换
git config --global core.autocrlf false

# warn: 当 Git 检测到文件中有混合换行符时,它不会阻止提交,但会给用户发出警告信息
# false: Git 不会检查文件中的换行符一致性,也不会阻止提交包含混合换行符的文件
# true: Git 将拒绝提交任何包含混合换行符的文件
git config --global core.safecrlf warn

# 防止路径被转义为八进制
git config --global core.quotepath false

github加速

添加如下内容到 ~/.gitconfig

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/

alias 提高效率

1
2
3
4
5
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.logg "log --graph --decorate --all"

配置了 alias,就可以简化相应的 Git 命令,例如 git status 可以简化为 git st

Git 的 git log 并不能显示其他的分支,以及分支之间的树形关系,所以额外添加很多的参数,因此,适合用 git logg 这么一个别名来代替。

对比一下`git log` 和 `git logg` 的差异。

git log 不能够显示分支之间的树形关系,git logg可以。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
commit 68b7f2f13b73cfdaeadc022eb02181714449186c (HEAD -> master, origin/master, origin/HEAD)
Author: natsql <natsql@example.com>
Date:   Mon Nov 25 00:08:01 2019 +0800

    fix title

commit b65de90b15ef78c12b2ac9346520c873504b361c
Author: natsql <natsql@example.com>
Date:   Mon Nov 25 00:01:13 2019 +0800

    add quick rust
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ git logg
* commit 68b7f2f (HEAD -> master, origin/master, origin/HEAD)
| Author: natsql <natsql@example.com>
| Date:   Mon Nov 25 00:08:01 2019 +0800
|
|     fix title
|
| * commit 01dfa04 (origin/dependabot/npm_and_yarn/lodash-4.17.15)
|/  Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
|   Date:   Sun Nov 24 16:01:47 2019 +000

结合 --oneline 参数很方便地浏览提交记录。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ git logg --oneline
* 68b7f2f (HEAD -> master, origin/master, origin/HEAD) fix title
| * 01dfa04 (origin/dependabot/npm_and_yarn/lodash-4.17.15) Bump lodash from 4.17.11 to 4.17.15
|/
| * 387e6da (origin/dependabot/npm_and_yarn/lodash.merge-4.6.2) Bump lodash.merge from 4.6.1 to 4.6.2
|/
| * 32a2929 (origin/dependabot/npm_and_yarn/mixin-deep-1.3.2) Bump mixin-deep from 1.3.1 to 1.3.2
|/
* b65de90 add quick rust
* 228f94a update comments.js
...

与版本号相关的命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 1. 获取分支名:
$ git name-rev --name-only  HEAD
master

# 2. 获取最近一次的commit:
$ git --work-tree ./ rev-parse "HEAD^{commit}" 2>/dev/null

# 3. 如下命令返回为空,就是clean; 否则就是dirty
$ git --work-tree ./ status --porcelain 2>/dev/null
# git describe --dirty 只考虑对现有文件的更改,但这是有问题的,因为新的未跟踪的 .go 文件会影响构建,因此使用 git status 中查出来的结果

# 4. 使用 `git describe`命令从tags中查询version。 只要有tag,并且以v开头,就会查出来
# 查询出来的结果: 最近的tag号-最近提交和tag之间的提交次数-g{commit_id的前14位}
# the current head of my "parent" branch is based on v1.0.4, but since it has a few commits on top of that,
# describe has added the number of additional commits ("664") and an abbreviated object name for the commit itself ("f0120fe16f866e") at the end.
$ git --work-tree ./ describe --tags --match='v*' --abbrev=14 "f0120fe16f866ed7fdd7644464083734de247733^{commit}" 2>/dev/null
v1.0.4-664-gf0120fe16f866e

专题:

本文发表于 2022-09-14,最后修改于 2022-09-14。

本站永久域名「 jiavvc.top 」,也可搜索「 后浪笔记一零二四 」找到我。


上一篇 « kerberos概述 下一篇 » gnu

赞赏支持

请我吃鸡腿 =^_^=

i ysf

云闪付

i wechat

微信

推荐阅读

Big Image