我喜欢git索引允许的细粒度提交,即在最终提交之前通过git add暂存单个文件甚至块。不幸的是,有时在花了一些时间准备一个特定的提交之后,肌肉记忆就开始起作用了,所以我git commit -a -m "msg"了。然后我要么不得不接受它,要么跳过一些reset或--amend的圈套。
有没有办法让我(理想情况下是全局的)配置Git,这样如果我发出一个git commit -a,它就会被拦截?也许是一个脚本,要求我确认是否真的要提交所有内容?我考虑过将提交操作委托给包装器脚本(例如,"gitcommit"),但不要认为这会很好地工作,因为它不会阻止我执行git commit -a -m "msg",这首先就是问题所在。
发布于 2010-11-30 08:14:13
试试pre-commit hooks
类似这样的东西(未测试)
.git/hooks/pre-commit
#!/bin/sh
git diff-files --quiet # check if the working directory have non-staged files
DIRTY_WORKING=$?
if [ ! $DIRTY_WORKING ] ; then # check if we are committing all files
# list all files to be committed
git diff-index --name-status --cached HEAD
echo "Are you sure? (type YES to continue)"
read VALUE
[ "x$VALUE" != "xYES" ]
exit $?
fi
exit 0您可以使用git diff-index --cached HEAD | wc -l来查看要提交的文件数。但我想我会把这个留给你自己。
发布于 2010-11-30 07:48:21
一种方法是使git成为一个别名,它运行您创建的脚本,该脚本查看命令行参数,并让您知道是否在命令行上输入了commit和-a。
就我个人而言,我从不使用commit -a,而总是使用git add -u和git commit。
https://stackoverflow.com/questions/4309181
复制相似问题