基本 Git 配置
介绍
链接
您可以在lobotuerto 的笔记 - 基本 Git 配置中查看本文的最新更新版本。
介绍
如果您是Manjaro Linux用户,那么您的机器中已经有Git 。
如果您是Ubuntu用户,请使用以下命令安装:
sudo apt install git
你可以用这个来检查它是否正常工作:
git --version
# git version 2.17.1
让我们进行一些基本设置,以便我们能够初始化新项目并进行提交。
用户和电子邮件
Git将使用这些数据来标记您创建的任何提交:
git config --global user.name "Your name goes here"
git config --global user.email "your@email.goes.here"
丰富多彩的CLI
git status
执行和时获得彩色输出git diff
:
git config --global color.ui "auto"
CPU 线程
要启用自动检测用于打包存储库的 CPU 线程:
git config --global pack.threads "0"
有用的别名
将其添加到您的~/.gitconfig
:
[alias]
l = log --oneline --decorate --graph
ll = log --graph --abbrev-commit --decorate --date=relative \
--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) \
%C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
lll = log --graph --abbrev-commit --decorate --date=relative \
--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) \
%C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' \
--branches
co = checkout
ci = commit
man = help
h = help
a = add
f = fetch
d = diff
dc = diff --cached
dt = difftool
dtc = difftool --cached
ds = diff --stat
dsc = diff --stat --cached
s = status --short --branch
b = branch
[credential]
helper = cache
[diff]
algorithm = patience
全局 .gitignore
让我们定义一个全局的.gitignore文件:
git config --global core.excludesfile ~/.gitignore_global
让我们用它来忽略Visual Studio Code项目文件以及ElixirLS插件生成的文件:
echo ".vscode/" >> ~/.gitignore_global
echo ".elixir_ls/" >> ~/.gitignore_global
处理行尾
Linux / Mac
如果您是Linux / Mac用户:
git config --global core.autocrlf input
git config --global core.safecrlf true
视窗
如果您是Windows用户:
git config --global core.autocrlf true
git config --global core.safecrlf true