问题
I would rather make temporary commits than use the git stash. More importantly, I would prefer my colleauges with less experience with git avoid the stash.
Is there a way to disable the git stash so that commands that interact with it terminate with an error?
EDIT: Thanks for the answers suggesting what I can do instead, but what I am really looking for is a "yes" or "no" answer, if possible with some justification, to the literal question.
回答1:
Replace it with a script:
cd /usr/lib/git-core
mv git-stash git-stash.backup
echo "#!/bin/sh
echo git stash is disabled, please commit your changes" > git-stash
chmod a+rx git-stash
回答2:
I once answered a similar question.
In your case, the function could be:
function git () {
if [ "$1" = "stash" ];then
echo '"git stash" is disabled, try "git commit" instead'
exit 1
else
command git $@
fi
}
But this function is not robust at all. It can prevent commands starting with git stash
, but you can easily bypass it with a command like git '' stash
or git --git-dir=foo.git stash
. How to test if the command is essentially git stash
is another problem. Besides, the function can't affect Git plugins in other tools. And I don't think this solution gives a good direction. Ideally Git should have a switch to enable/disable some of its sub-commands but I'm afraid it's another big problem.
If I get it right, the problem is that you want your less experienced colleagues to avoid git stash
so that they would make fewer troubles. It's unfair. It would be nice, if you, as an experienced Git user, take responsibility for training them how to use git stash
and its sub-commands properly. Show them the power and beauty of git commands. After all, git stash
is not too hard to grasp. They are programmers. They can learn.
Believe me, for less experienced Git users who know little about Git internals, replacing git stash
with git commit
would be a disaster. They will definitely push needless commits and haunt you with a lot of questions.
来源:https://stackoverflow.com/questions/49768206/can-i-disable-the-git-stash