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

相关推荐
江畔柳前堤1 小时前
github实战指南07-CLI 与高级技巧
前端·人工智能·chrome·深度学习·github·caffe·issue
右耳朵猫AI1 小时前
GitHub周趋势2026W23 | last30days-skill AI搜索、headroom令牌压缩、apple/container开源
人工智能·开源·github
器灵科技2 小时前
AI视频工具实测:Seedance/可灵/HappyHorse谁最能打?
java·运维·数据库·人工智能·github
DogDaoDao2 小时前
【GitHub】 Headroom 深度解析:AI Agent 上下文压缩层的完整技术拆解
人工智能·深度学习·程序员·github·ai agent·智能体·agent skill
dominciyue3 小时前
当 judge 们吵起来时,别再投票了:用执行结果给 code eval 一个 ground truth
github
IT 行者3 小时前
GitHub Spec Kit 实战(六):/speckit.implement 怎么用、怎么审、怎么发现 spec 阶段的遗漏——五部曲收官
java·驱动开发·github·ai编程·claude
带娃的IT创业者3 小时前
深度解析:从 GitHub 热门项目看 SEO 自动化的技术架构演进
架构·自动化·github·seo·技术架构·反爬虫
SCandL1524 小时前
自动化ai测试
github
IT 行者4 小时前
GitHub Spec Kit 实战(四):读懂和干预 /speckit.plan——AI 最自由发挥的一步
java·人工智能·github·ai编程·claude
小李不困还能学7 小时前
用git GUI往远程仓库中添加文件/文件夹
git