git stash 命令确实有点好用

2022-08-26 13:36:59 +08:00
 wdssmq

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

所以每次还要先执行下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

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

4034 次点击
所在节点    git
24 条回复
vision1900
2022-08-26 13:45:23 +08:00
俺也来 show 下自己的 git alias 和 function: https://github.com/librz/shell-scripts/blob/main/.zshrc#L100
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
2022-08-26 13:59:41 +08:00
代码经常 stash 完就永远躺在那里了 🐶
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
2022-08-26 14:13:03 +08:00
fork 用户表示自己已经废了
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
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
2022-08-26 14:24:59 +08:00
@LindsayZhou
试试 git log --oneline --decorate --graph
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
2022-08-26 14:42:22 +08:00
@wjfz #8
没我的漂亮 :P
能看到其他分支的位置也方便一点。

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

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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/875573

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX