相关疑难解决方法(0)

更改默认的git hooks

不确定这是否可以在git中使用(我没有找到它,但我可能在我的搜索中使用了错误的词汇表),但是能够修改和启用钩子作为所有新存储库的默认值是有用的(在我的意思是创建的时间)所以每次创建新的存储库时都不必自定义这些.看起来这样做的简单方法是编写一个包装器,在我创建一个新的存储库时设置我的钩子和chmods,但如果有一种内置到git中的方法,我宁愿使用它而不是使用不必要的包装器脚本,而不是四处闲置.


澄清从评论复制到现在删除的答案:

我的问题是,是否可以更改所有新存储库的默认行为,因此不需要每次为每个新存储库以相同的方式自定义它们.简单的答案是编写一个包装器来创建和自定义repos(它生成钩子脚本并对它们进行chmod),但似乎这个默认行为也应该是可自定义的,而不必这样做.

git githooks

35
推荐指数
3
解决办法
2万
查看次数

使用预提交挂钩停止特定作者的git提交

我的计划是使用git来跟踪/ etc中的更改但是在提交时我希望让进行更改的人通过在命令行上添加--author选项将自己指定为作者.

所以我想以root身份停止意外提交.

我尝试创建这个预提交钩子但它不起作用 - 即使我在提交行上指定了作者,git var仍然会返回root.

AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
if [ "$AUTHOR" == "root <root@localhost>" ];
then
   echo "Please commit under your own user name instead of \"$AUTHOR\":"
   echo 'git commit --author="Adrian"'
   echo "or if your name is not already in logs use full ident"
   echo 'git commit --author="Adrian Cornish <a@localhost>"'
   exit 1
fi
exit 0
Run Code Online (Sandbox Code Playgroud)

git hook pre-commit

13
推荐指数
1
解决办法
5063
查看次数

如何防止 Git 自动检测 user.email?

我没有故意进行任何全局user.email或全局user.name设置。

我喜欢使用git config user.emailgit config user.name命令为每个 repo 设置我的 user.email 和 user.name 。

在带有 git 版本 2.17.0 的 macOS 上,如果我忘记在 Mac 上设置user.emailuser.name获取 repo,当我运行时,git commit我会收到此错误:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'lone@mymac.(none)') …
Run Code Online (Sandbox Code Playgroud)

git configuration git-commit

6
推荐指数
1
解决办法
1226
查看次数

禁用 Git 全局用户名和电子邮件

我想为我的 git 用户禁用他们可以设置全局用户名和电子邮件的选项。我希望它完全是的。

现在我遇到了问题,当他们中的一些人设置global user.nameand 时global user.email,所有提交的代码在每个项目中都使用相同的名称。

我怎么解决这个问题?

git git-config git-commit

1
推荐指数
1
解决办法
198
查看次数