基本 Git 配置 介绍 链接

2025-06-07

基本 Git 配置

介绍

链接


您可以在lobotuerto 的笔记 - 基本 Git 配置中查看本文的最新更新版本。


介绍

如果您是Manjaro Linux用户,那么您的机器中已经有Git 。

如果您是Ubuntu用户,请使用以下命令安装:

sudo apt install git
Enter fullscreen mode Exit fullscreen mode

你可以用这个来检查它是否正常工作:

git --version
# git version 2.17.1
Enter fullscreen mode Exit fullscreen mode

让我们进行一些基本设置,以便我们能够初始化新项目并进行提交。

用户和电子邮件

Git将使用这些数据来标记您创建的任何提交:

git config --global user.name "Your name goes here"
git config --global user.email "your@email.goes.here"
Enter fullscreen mode Exit fullscreen mode

丰富多彩的CLI

git status执行和时获得彩色输出git diff

git config --global color.ui "auto"
Enter fullscreen mode Exit fullscreen mode

CPU 线程

要启用自动检测用于打包存储库的 CPU 线程:

git config --global pack.threads "0"
Enter fullscreen mode Exit fullscreen mode

有用的别名

将其添加到您的~/.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
Enter fullscreen mode Exit fullscreen mode

全局 .gitignore

让我们定义一个全局的.gitignore文件:

git config --global core.excludesfile ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode

让我们用它来忽略Visual Studio Code项目文件以及ElixirLS插件生成的文件:

echo ".vscode/" >> ~/.gitignore_global
echo ".elixir_ls/" >> ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode

处理行尾

Linux / Mac

如果您是Linux / Mac用户:

git config --global core.autocrlf input
git config --global core.safecrlf true
Enter fullscreen mode Exit fullscreen mode

视窗

如果您是Windows用户:

git config --global core.autocrlf true
git config --global core.safecrlf true
Enter fullscreen mode Exit fullscreen mode

链接

基础知识

高级用例

托管服务

文章来源:https://dev.to/lobo_tuerto/basic-git-configuration-5545
PREV
新 Vue.js 项目的快速入门指南 意见 成功设置新 Vue.js 应用程序 链接
NEXT
🔥 如何在 2024 年学习 RAG:从初学者到专家(循序渐进)🚀