如何需要git的复位确认 - 硬? [英] How to require confirmation for git reset --hard?
问题描述
我如何确保混帐要求确认任何硬复位?
How to I make sure that git asks for confirmation on any hard reset?
我有过几次。终端窃听了(bash的历史记录导航),给我只能在命令的最后一部分......我pressed进入,让我吃惊的重置我所有的变化。
I have had this several times. The terminal bugged out(bash history navigation) and showed me only the last part of the command... I pressed enter and to my surprise reset all my changes.
那么,有没有一种方法,以确保在正常运行的git要求进行确认执行硬重置时?
So is there a way to make sure that under normal operation git asks for a confirmation when performing a hard reset?
推荐答案
Git的本身并没有实现这个(好!),而这是不可能的别名内置的Git命令,所以我认为有两种方式:
Git itself doesn't implement this (for good!), and it's impossible to alias a built-in Git command, so I see two ways:
-
一个自定义包装—像
A custom wrapper — something like
# cat >/usr/local/bin/mygit
#!/bin/sh
set -e -u
if [ $# -ge 2 ]; then
if [ "x$1" = "xreset" -a "x$2" = "x--hard" ]; then
echo 'Sure?'
read resp || exit $?
test "x$resp" = "xyes" || exit 0
fi
fi
git "$@"
^D
# chmod +x $_
$ mygit reset --hard
壳牌别名:
Shell aliases:
cat >>~/.bashrc
alias git /usr/local/bin/mygit
^D
其中,的/ usr / local / bin目录/ mygit
从previous点取。
Where /usr/local/bin/mygit
is taken from the previous point.
更新以纳入威廉Pursell&MDASH的建议;外壳functon其中覆盖的外部命令:
Update to incorporate the suggestion of William Pursell — a shell functon which "overrides" the external command:
# cat >>~/.bashrc
git() {
set -e -u
if [ $# -ge 2 ]; then
if [ "x$1" = "xreset" -a "x$2" = "x--hard" ]; then
echo 'Sure?'
read resp || return $?
test "x$resp" = "xyes" || return 0
fi
fi
command git "$@"
}
^D
之后,平原混帐等等...
在shell会调用包装函数,而直接的/ usr / bin中/混帐
将直接调用的Git。
After that, plain git blah ...
in a shell would call the wrapper function while direct /usr/bin/git
would call Git directly.
这篇关于如何需要git的复位确认 - 硬?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!