Git | 配置别名操作

基本概念

  • 作用 ------ 通过简短的别名替代复杂的 Git 命令,提高效率

  • 配置级别

    • 命令加 --global / 修改 ~/.gitconfig 文件 ------ 对 当前用户的所有仓库 生效
    • 命令不加 --global / 修改 .git/config 文件 ------ 对 当前仓库 生效

命令行配置别名

  • st 表示 status ,查看 Git 仓库状态

    shell 复制代码
    $ git config --global alias.st status
    $ git st
  • ci 表示 commit,提交代码

    shell 复制代码
    $ git config --global alias.ci commit
    $ git ci -m "bala bala bala..."
  • unstage 表示 reset HEAD,撤销暂存区的修改

    shell 复制代码
    $ git config --global alias.unstage 'reset HEAD'
    $ git unstage test.py
  • last 表示 log -1,显示最后一次提交信息

    shell 复制代码
    $ git config --global alias.last 'log -1'
    $ git last
    commit adca45d317e6d8a4b23f9811c3d7b7f0f180bfe2
    Merge: bd6ae48 291bea8
    Author: Michael Liao <askxuefeng@gmail.com>
    Date:   Thu Aug 22 22:49:22 2013 +0800
    
        merge & fix hello.py
  • lg 表示 log --color --graph ...,自定义的彩色日志格式

    shell 复制代码
    $ 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"
    $ git lg

文件配置别名

  • 配置当前仓库 ------ 修改项目根目录 .git/config 文件

    ini 复制代码
    $ cat .git/config 
    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
    [remote "origin"]
        url = git@github.com:michaelliao/learngit.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
        remote = origin
        merge = refs/heads/master
    [alias]
        last = log -1
  • 配置当前用户的所有仓库 ------ 修改用户主目录 .gitconfig 文件

    ini 复制代码
    $ cat .gitconfig
    [alias]
        co = checkout
        ci = commit
        br = branch
        st = status
    [user]
        name = Your Name
        email = your@email.com

相关推荐
-拟墨画扇-5 小时前
Git | 多人协助策略
git·gitee·github·gitcode
BestOrNothing_20155 小时前
Git 原理彻底讲透:工作区 / 暂存区 / 本地仓库 / origin 一次理清(VSCode 可视化 + 实战避坑)
git·分支开发·fetch / merge·add / commit·pull / push·工作区/暂存区/本地仓库
Huazzi.5 小时前
使用Scoop安装Git
git·elasticsearch·gitee·ssh·github·scoop
NocoBase5 小时前
GitHub Star 数量前 12 的 AI 工作流项目
人工智能·低代码·开源·github·无代码
马达加斯加D6 小时前
git --- reset 删除提交
git
10000hours6 小时前
【Git】git常用命令
git
无双@6 小时前
Github BettaFish 微舆docker部署教程 —— 打造你的八卦天团!
docker·容器·开源·github·微舆·bettafish
emem.6 小时前
【超详细】VSCode连接GitHub全攻略:上传/克隆代码一步到位
ide·vscode·github
猫头虎6 小时前
猫头虎AI分享|可把GitHub代码库变成实时文档中心的一款实用型MCP工具:GitMCP,让AI随时访问最新文档代码,消除代码幻觉
人工智能·github·aigc·ai编程·ai写作·agi·ai-native