简体   繁体   English

git-我可以为我的仓库提供公共的首选配置设置吗?

[英]git - Can I have public preferred config settings for my repo?

I'd like to do something like force anyone from committing trailing whitespace to my branch by showing them an error rather than allow the commit. 我想做一些类似的事情,通过向他们显示错误而不是允许提交来迫使任何人将尾随空白提交到我的分支。 I know I can add something to .git/config but I'm interested in doing something so that when the repo is cloned the file is still there like .gitignore. 我知道我可以在.git / config中添加一些内容,但是我有兴趣做一些事情,以便克隆存储库时文件仍然像.gitignore一样存在。 Does git allow for something like that with config? git是否允许使用config这样的东西?

The config cannot be cloned. 该配置无法克隆。

You could setup a template directory that the users would need to use when cloning your repo ( git clone ): 您可以设置一个模板目录 ,供用户在克隆存储库时需要使用( git clone ):

git clone --template=/path/to/template/folder /url/of/your/repo

That would allow a custom .git/config to be copied in the cloned repo (with a apply.whitespace set to error ). 这将允许将自定义.git/config复制到克隆的apply.whitespace (将apply.whitespace设置为error )。

But that means the users have to use that option. 但这意味着用户必须使用该选项。


The other option is to setup a pre-receive hook on the bare repo your colleagues would push to, in order to reject the commit if whitespace errors are detected. 另一个选择是在同事将要推送的裸仓库上设置一个预接收钩子,以便在检测到空白错误时拒绝提交。
Centralizing that constraint allows the users to have the settings they want locally, since that particular option is enforced on the push in the central (bare) repo. 集中约束可以使用户在本地具有他们想要的设置,因为在中央(裸露)存储库中的推送上会强制执行该特定选项。

Example of such an hook: this gist, ruby script (extract) 此类钩子的示例: 该要点,红宝石脚本 (摘录)

#!/usr/bin/env ruby

old_sha, new_sha, ref = STDIN.read.split(' ')

diff = %x{ git diff --raw --name-only #{old_sha} #{new_sha} 2> /dev/null }

diff.each_line do |line|
file = line.chomp
next unless file =~ /\.rb\Z/i

tree = %x{ git ls-tree --full-name #{new_sha} #{file} 2> /dev/null }.split(" ")

contents = %x{ git cat-file blob #{tree[2]} 2> /dev/null }

if found = contents.each_line.map(&:chomp).find{ |e| e =~ /\s+\Z/ }
puts <<EOF
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> !!!!!!!!! PUSH REJECTED !!!!!!!!!
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>
> REMOVE TRAILING WHITESPACE.
>  * #{tree[3]}
>
>  #{found.inspect}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在自己的存储库中有一个克隆的git存储库吗? - Can I have a cloned git repo inside my own repo? 如何在另一个目录中的单个Git仓库中管理不同目录中的Linux设置(config)文件? - How can I manage Linux settings (config) files in different directories in a single Git repo in another directory? 我可以在仓库中指定.git / config值吗 - Can I specify .git/config values in a repo `yarn install` 正在更改我的 repo's.git/config 文件。 我怎样才能找到原因? - `yarn install` is changing my repo's .git/config file. How can I track down why? 我可以将SVN存储库用作GIT存储库的源吗 - Can I have an SVN Repo as a source for a GIT Repo 是否有首选路径,我应该在Mac OS X上初始化我的Git仓库? - Is there a preferred path where I should initialise my Git repo on Mac OS X? 我可以删除我当地的.git仓库吗? - Can I delete my local .git repo? 如果我的服务器上有GIT repo(裸),我可以轻松地将它移动到另一台服务器吗? - If I have a GIT repo (bare) on my server, can I move it to another server easily? 当我更改Git配置用户名时,公钥会受到影响吗? - Will the public key affected, when I change my Git config username? 我的.git / config中没有origin远程。 我该如何解决这个问题? - I don’t have an origin remote in my .git/config. How can I fix that?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM