比.gitignore更强大的方式来保持(强制)文件回购吗? [英] What are some more forceful ways than a .gitignore to keep (force) files out of a repo?

查看:111
本文介绍了比.gitignore更强大的方式来保持(强制)文件回购吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管这些文件位于.gitignore文件中,推测是使用 git add --all -f ,但我的开发团队中的人员仍然继续将构建特定文件(node_modules和其他文件)推送到我们的回购站。 c $ c>或者与之相关的东西。

这是一个巨大的痛苦,让人们停止这样做很困难。



有什么办法可以将某些文件推送到repo上吗?

解决方案


有什么办法可以将某些文件推送到回购站点上吗?

是的,您可以像这样使用钩子来阻止提交多个文件。



pre-receive hook



#!/ bin / sh

#检查这是否是存储库中的第一次提交
如果git rev-parse --verify HEAD> / dev / null 2>& 1
然后
#我们将我们的更改与之前的提交
进行比较,比较= HEAD ^
else
#初始提交:针对空树对象的差异
针对= 4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

#将输出重定向到屏幕。
exec 1>& 2

#检查是否已更新给定文件
if [$(git diff-tree -r --name-only $ against | grep<任何你想要在这里找到的文件>)];
然后

#输出颜色
red ='\033 [0; 31m';
green ='\033 [0; 32m';
yellow ='\033 [0; 33m';
default ='\033 [0; m';

#personal touch :-)
echo$ {red}
echo
echo| ZZzzz
echo|
echo|
echo| ZZzzz / ^ \ | ZZzzz
echo| | ~~~ | |
echo| | - - | / \
echo/ ^ | \\ | [] + | | ^^^ |
echo| ^^^^^^^ | | + [] | | |
echo | + [] | / \ / \ / \ / \ ^ / \ / \ / \ / \ / | ^^^^^^^ |
echo| + [] + | ~~~~~~~~~~~~~~~~~~ | + [] |
echo| | [] / ^ \ [] | + [] + |
echo| + [] + | [] || || [] | + [] + |
echo| [] + | || || | [] + |
echo| _______ | ------------------ | _______ |
ec ho
echo
echo$ {green}您刚刚提交了代码
echo$ {red}您的代码$ {yellow}很糟糕。
echo$ {red}不要再次提交
echo
echo$ {default}
fi;

#根据您的需要设置退出代码为0或1
#0 =好推
#1 =退出而不推动
退出0;






注意:



Github不支持以这种方式使用挂钩。

他们有自己的 WebHooks


可以在客户端使用钩子。

在客户端客户端可以在 pre-commit 钩子中放置相同的代码


People on my dev team keep on pushing build specific files (node_modules and others) onto our repos despite these files being in a .gitignore file, presumably with git add --all -f or something related to that.

It's a huge pain and getting people to stop doing it is proving difficult.

Is there some way I can make it totally impossible to push certain files onto a repo?

解决方案

Is there some way I can make it totally impossible to push certain files onto a repo?

Yep, You can use hooks like this to prevent several files to be committed.

pre-receive hook

#!/bin/sh

# Check to see if this is the first commit in the repository or not
if git rev-parse --verify HEAD >/dev/null 2>&1
then
    # We compare our changes against the previous commit
    against=HEAD^
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Redirect output to screen.
exec 1>&2

# Check to see if we have updated the given file
if [ $(git diff-tree -r --name-only $against | grep <ANY FILE YOU WANT TO FIND OUT HERE> ) ];
then

    # Output colors
    red='\033[0;31m';
    green='\033[0;32m';
    yellow='\033[0;33m';
    default='\033[0;m';

    # personal touch :-)
    echo "${red}"
    echo "                                         "
    echo "                   |ZZzzz                "
    echo "                   |                     "
    echo "                   |                     "
    echo "      |ZZzzz      /^\            |ZZzzz  "
    echo "      |          |~~~|           |       "
    echo "      |        |-     -|        / \      "
    echo "     /^\       |[]+    |       |^^^|     "
    echo "  |^^^^^^^|    |    +[]|       |   |     "
    echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
    echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
    echo "  |       |  []   /^\   []   |+[]+   |   "
    echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
    echo "  |[]+    |      || ||       |[]+    |   "
    echo "  |_______|------------------|_______|   "
    echo "                                         "
    echo "                                         "
    echo "      ${green}You have just committed code  " 
    echo "      ${red}Your code ${yellow}is bad.!!!      "
    echo "      ${red} Do not ever commit again    "
    echo "                                         "
    echo "${default}"
fi;

# set the exit code to 0 or 1 based upon your needs
# 0 = good to push
# 1 = exit without pushing.
exit 0;


Note:

Github does not support using hooks in this way.
They have their own WebHooks

In this case you can use hooks as well but on the client side.
The same code can be placed inside pre-commit hook on the client side.

这篇关于比.gitignore更强大的方式来保持(强制)文件回购吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆