防止运行没有其他参数的git stash [英] Prevent `git stash` with no additional arguments from running

查看:85
本文介绍了防止运行没有其他参数的git stash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道是否可以修改git,因此它只会拒绝git stash,而是要求我显式指定git stash push.当我想检查存储区(git stash list)时,经常发现自己不小心存储了东西.同样,如果我在索引中添加内容然后执行git stash(并且忘记添加--keep-index),这会很烦人.反过来可能会造成灾难性的后果( git stash/git stash pop弹出后如何恢复索引?)

Anyone know if it's possible to modify git so it will simply reject git stash and in stead require me to explicitly specify git stash push. I often find myself accidently stashing stuff when I wanna inspect the stash (git stash list). Similarly it's rather annoying if I have stuff in the index and then do git stash (and forget to add --keep-index). Which in turn can have disastrous consequences (How to recover the index after a git stash / git stash pop?)

推荐答案

将函数添加到~/.bashrc.

function git() {
  GIT=`which git`
  if [[ "$#" -eq 1 ]] && [[ "$1" = "stash" ]];then
    echo 'WARNING: run "git stash push" instead.'
  else
    $GIT $@
  fi
}

尽管我在Ubuntu和Windows上都尝试过,但都成功了,但是我不确定是否有可能导致错误的副作用.

Though I tried on Ubuntu and Windows and both succeeded, I'm not sure if there's any side effect that may cause bugs.

这篇关于防止运行没有其他参数的git stash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆