V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
wdssmq
V2EX  ›  git

git stash 命令确实有点好用

  •  
  •   wdssmq · 2022-08-26 13:36:59 +08:00 · 3979 次点击
    这是一个创建于 571 天前的主题,其中的信息可能已经有所发展或是发生改变。

    下边是我定义的命令别名,虽然还是记不住;

    所以每次还要先执行下code ~/.gitconfig打开配置文件照着敲;

    [alias]
        # status
        s   = status
        ss  = status --short --branch
    
        # stash
        sh  = stash
        shp = stash pop
        shl = stash list
        shs = stash save
        sha = stash apply
        std = stash drop
    
        # branch
        br  = branch
        bra = branch -a
        brm = branch -m
        co  = checkout
        cob = checkout -b
        sw  = switch
        swc = switch -c
    
        # remote
        ra  = remote add
        rao = remote add origin
        ru  = remote set-url
        ruo = remote set-url origin
        # re  = remote
        rev = remote -v
    
        # fetch
        fe  = fetch
        fep = fetch -p
        fo  = fetch origin
        fop = fetch origin -p
    
        # merge
        mr  = merge
        mnc = merge --no-commit
        # msq = merge --squash
    
        # commit
        ci  = commit
        cim = commit -m
    

    「折腾」 git 及 docker 命令快捷输入_电脑网络_沉冰浮水:

    https://www.wdssmq.com/post/20171130103.html

    ↑ 原文链接,后续可能会修改或补充

    24 条回复    2022-08-27 13:52:13 +08:00
    vision1900
        1
    vision1900  
       2022-08-26 13:45:23 +08:00   ❤️ 1
    俺也来 show 下自己的 git alias 和 function: https://github.com/librz/shell-scripts/blob/main/.zshrc#L100
    wcp1231
        2
    wcp1231  
       2022-08-26 13:51:54 +08:00
    我只用 oh-my-zsh 提供的这两个

    ```
    gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
    gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"'
    ```
    rpman
        3
    rpman  
       2022-08-26 13:59:41 +08:00   ❤️ 13
    代码经常 stash 完就永远躺在那里了 🐶
    LindsayZhou
        4
    LindsayZhou  
       2022-08-26 14:03:37 +08:00
    我 gitconfig 里的 alias 只有一个比较长的,用来看分支树状图,忘了哪里抄的了。
    ```
    lg = log --graph --abbrev-commit --decorate --all --format=format:\"%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(dim white) - %an%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)\"
    ```

    其他的有自动补全和说明,按下 tab 就出来了,Arch 源里的包带了 bash completions 脚本
    BeautifulSoap
        5
    BeautifulSoap  
       2022-08-26 14:13:03 +08:00
    fork 用户表示自己已经废了
    stoluoyu
        6
    stoluoyu  
       2022-08-26 14:19:43 +08:00
    alias gst='git status'
    alias gss='git status -s'
    alias gsb='git status -sb'
    alias ga='git add'
    alias gpo='git push -u origin master'
    alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -- | less"

    这是我自定义的,还有一堆 prezto 的 git 插件自带的,很少用。
    LindsayZhou
        7
    LindsayZhou  
       2022-08-26 14:24:05 +08:00
    @LindsayZhou #4
    不知道 OP 是啥系统,不过 completion 脚本在这里:
    https://github.com/git/git/tree/master/contrib/completion

    zsh 的也有,zsh 的应该是扔到 `/usr/share/zsh/site-functions/_git ` ,iirc
    wjfz
        8
    wjfz  
       2022-08-26 14:24:59 +08:00
    @LindsayZhou
    试试 git log --oneline --decorate --graph
    wjfz
        9
    wjfz  
       2022-08-26 14:36:13 +08:00
    ohmyzsh 自带的 git 插件很好用,另外补充一点自己的

    alias gcob="gco -b"
    alias ggpp="ggpnp"
    alias gx="git pull origin develop --rebase"
    alias gs="git show"
    alias gcml="gcm && gl"
    alias gl="git pull --rebase"
    LindsayZhou
        10
    LindsayZhou  
       2022-08-26 14:42:22 +08:00
    @wjfz #8
    没我的漂亮 :P
    能看到其他分支的位置也方便一点。

    https://sm.ms/image/jV12HKwyYLvuncJ
    magic3584
        11
    magic3584  
       2022-08-26 14:53:54 +08:00
    fork 不香吗
    wdssmq
        12
    wdssmq  
    OP
       2022-08-26 15:20:33 +08:00
    @BeautifulSoap #5
    @magic3584 #11

    从刚入坑 git 时就用了乌龟,开始用 wsl 后才真正开始尝试命令行;
    pengtdyd
        13
    pengtdyd  
       2022-08-26 15:54:50 +08:00
    说实话我不太喜欢用别名,我喜欢用全名。
    shm7
        14
    shm7  
       2022-08-26 16:13:04 +08:00
    一般拿来一键还原修改,哈哈
    lljxww
        15
    lljxww  
       2022-08-26 16:15:29 +08:00
    @wjfz ohmyzsh 里有这条: alias gup="git pull --rebase"
    menget
        16
    menget  
       2022-08-26 16:20:57 +08:00
    @rpman 真实,哈哈
    fxxkgw
        17
    fxxkgw  
       2022-08-26 16:35:53 +08:00
    我也特别喜欢用这个 然后结合 beyond compare
    TerranceL
        18
    TerranceL  
       2022-08-26 17:07:21 +08:00
    除了 git adog 之外其他全靠补全和 ctrl+r
    lujiaosama
        19
    lujiaosama  
       2022-08-26 17:12:21 +08:00   ❤️ 1
    git stash list 躺着一堆不知道什么时候的记录.
    Rache1
        20
    Rache1  
       2022-08-26 17:17:08 +08:00
    别名的话,zsh 的 git alias 就挺好,Windows 下可以使用 powershell ,配合下面这个 module 来实现。

    gluons/powershell-git-aliases: Oh My Zsh's Git aliases for PowerShell.
    https://github.com/gluons/powershell-git-aliases

    自己创建别名的话,直接在 powershell 的 $profile 里面添加函数就可以。
    whenov
        21
    whenov  
       2022-08-26 17:23:16 +08:00
    可惜不能只存 unstaged 区域的改动(--keep-index 也不行)
    yulang
        22
    yulang  
       2022-08-26 22:28:20 +08:00
    alias.amend=commit --amend --no-edit
    alias.glg=log --oneline --decorate --all --graph
    alias.refresh=pull --rebase --autostash upstream HEAD
    alias.discard=reset --hard HEAD
    gamesover
        23
    gamesover  
       2022-08-27 13:51:25 +08:00
    如果 lz 用 vs code 的话,推荐一款插件 gitgraph

    用了之后,你就从此告别自定义快捷键了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5402 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:55 · PVG 15:55 · LAX 00:55 · JFK 03:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.