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 分钟前
【C++】寻找数组中出现次数超过一半的数字:三种解法深度剖析
开发语言·c++·git·算法·leetcode·github·visual studio
一个程序猿老马12 小时前
012、远程协作:连接GitHub/Gitee与git remote
git·gitee·github
小柯博客14 小时前
STM32MP2安全启动技术深度解析
c语言·c++·stm32·嵌入式硬件·安全·开源·github
zhensherlock14 小时前
Protocol Launcher 系列:Tally 快速计数器的深度集成
前端·javascript·typescript·node.js·自动化·github·js
Lisonseekpan15 小时前
Git:如何将一个分支的特定提交合并到另一个分支?
java·大数据·git·后端·elasticsearch
pas13617 小时前
git 配置
git
独隅20 小时前
Git误操作急救手册
大数据·git·elasticsearch
水无痕simon20 小时前
03 Git 工作流程
git
一个程序猿老马1 天前
013、推送与拉取:git push与git pull的协作流程
大数据·git·elasticsearch
darkb1rd1 天前
OpenMythos:从零重构大模型架构实战指南
开源·github·好物分享