Git技巧

作者: 熊本猫 | 来源:发表于2018-08-13 18:22 被阅读0次

git设置快捷键/快捷方式

首先打开.gitconfig文件

vi ~/.gitconfig
.gitconfig示例

在.gitconfig中添加 [alias] 标签,在后面加上要定义的快捷键和内容,注意“快捷内容”是除去 git 后的部分,如:

pm = push origin HEAD:refs/for/master

对应的就是

git push origin HEAD:refs/for/master

将要定义的快捷键补充完之后,保存.gitconfig,就可以像这样直接使用了~

git pm示例

附上一些常用的快捷键

[alias]
    sed  = !git ls-files --stage | grep ^100 | awk '{print $4}' | xargs sed $@

    # 日志操作简化,并将日志格式化
    who = shortlog -n -s --no-merges
    lg  = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    lp  = log --color --pretty=oneline --abbrev-commit --graph --decorate
    lns = log --color --name-status --date=iso
    lst = log --color --stat --date=iso
    ldi = log --color --date=iso
    ldp = log --color --date=iso -p
    ls  = log --oneline
    # 最新一条 commit log 摘要
    l1  = !git --no-pager log --max-count=1 --date=iso
    # 最后一次提交的 hash 串
    lh  = rev-parse HEAD

    gpc= grep -n --color -E
    ci = commit
    co = checkout
    st = status
    # 查看远程分支,远程分支会用红色表示出来
    ba = branch -a
    bv = branch -v
    bm = branch -m
    bd = branch -d
    bc = checkout -b
    cb = checkout -b
    rt = reset --hard
    cp = cherry-pick -x
    nb = checkout -b
    mg = merge
    df = diff
    rv = remote -v
    fa = fetch --all
    # 刻意地创造提交线图分叉
    mnf = merge --no-ff
    rso = remote show origin
    # 清除除在本地有但在远程库中已经不存在的分支 git fetch -p
    rpo = remote prune origin

    # 'git add -u' 只包含刪除的檔案,不包含新增檔案
    # 'git add .' 包含修改和新增的檔案,但是不包含刪除
    # 'git addall' 通通加到 staging
    au = add -u
    awd= add .
    aa = !sh -c 'git add . && git add -u'

    # To list untracked files
    ut = ls-files --other --exclude-standard
    # list tracked files
    tf = ls-files
    # show modified files
    lm = ls-files -m
    # show deleted files
    ld = ls-files -d
    # show unmerged files

    lu = ls-files -u

    unstage  = reset HEAD
    uncommit = reset --soft HEAD^
    amend    = commit --amend

    # 使用 vimdiff 查看 diff 文件
    vdf = difftool

    # 临时保存
    ss = stash save
    sp = stash pop
    sl = stash list

相关文章

  • Git stash 技巧

    Git stash常用技巧 git stash save git stash list git stash app...

  • 2016-06-24 阅读整理

    Git Git 基础命令Git 分支管理Git 分支合并Git 公钥提交Git 常用技巧Git 设置别名 Andr...

  • GIT的使用

    ##git的使用技巧 git安装 mac端:1,下载Git installer,地址;http://git-scm...

  • 查看某一行代码的修改历史

    git小技巧:git blame && git show 查看某一行代码的修改历史 $ git log -L st...

  • git常用命令及使用技巧

    git常用命令及使用技巧.md git 客户端安装 Git客户端 下载地址: https://www.git-sc...

  • git 笔记

    git 使用技巧 git 介绍 记住,在 Git 中任何 已提交的 东西几乎总是可以恢复的。 甚至那些被删除的分支...

  • Git技巧

    git设置快捷键/快捷方式 首先打开.gitconfig文件 在.gitconfig中添加 [alias] 标签,...

  • git 技巧

    git clone 时直接提交用户名和密码git clone https://用户名:密码@地址 当用户名中包含...

  • Git技巧

    常用技巧

  • Git 技巧

    重置已经 push 到服务器的 commit 终端命令:git push 远端branch +comm...

网友评论

      本文标题:Git技巧

      本文链接:https://www.haomeiwen.com/subject/jtoubftx.html