在 VSCode 中使用以下命令成功安装预提交:
python3 -m pip install pre-commit --user
Run Code Online (Sandbox Code Playgroud)
但是当我尝试进行预提交安装时,我收到错误消息:
zsh: command not found: pre-commit
Run Code Online (Sandbox Code Playgroud) 在未对预提交配置文件进行更改的情况下,预提交运行突然失败。尝试初始化 Flake8 环境时,日志显示以下错误消息:
...
[INFO] Initializing environment for https://gitlab.com/pycqa/flake8.git.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
expected return code: 0
stdout: (none)
stderr:
fatal: could not read Username for 'https://gitlab.com': No such device or address
...
Run Code Online (Sandbox Code Playgroud)
预提交配置文件包含以下条目:
---
repos:
- repo: https://gitlab.com/pycqa/flake8.git
rev: 3.9.2
hooks:
- id: flake8
exclude: 'tests|env|docs'
Run Code Online (Sandbox Code Playgroud) 这可能是更多的技术问题:
我正在使用git进行版本控制,并使用rsync将PHP CMS的文件发送到测试或生产站点.现在,我想跟踪一个使用防呆和自动化系统当前部署的提交,我正在考虑这个问题:
设置一个git hook来添加/更新带有最新标记和提交哈希的文本文件.然后我可以轻松查找提交.
我的问题是,在预提交时,脚本将不知道提交哈希.是否有任何直接的方法来完成(或另一种方法达到相同的目的)?
感谢您提前输入!
我目前有一个包含两个项目的repo,每个项目都在自己的子文件夹中:一个在C#中,另一个在Javascript中.我想有一个预提交钩子,它将运行jshint,但只有当任何暂存文件在Javascript文件夹中时如果暂存文件只来自C#文件夹,那么预提交钩子将不会运行.
这有可能吗?或者是我将这两个项目拆分成自己的回购的唯一解决方案?
第一个问题......甚至有可能用git来完成这个吗?:)
我想要的是这个:
有时,为了自己的调试目的,我将代码中的一个变量切换为true
( localMode = true;
)。但这不应该被提交。我应该只提交变量设置为false
. 当然,有时我会忘记进行此更改。如果我即将提交“错误”代码,git 是否有可能以某种方式停止或警告我?
UPD:
感谢您的帮助!我最终得到了以下 shell 脚本:
#!/bin/bash
git diff --cached --name-only | while read FILE; do
if [[ $(echo "$FILE" | grep -E "^.+main\-controller\.js$") ]]; then
content=$(<"$FILE")
if [[ $(echo "$content" | grep -E "rootScope\.localMode = true") ]]; then
echo -e "\e[1;31m\tCommit contains localMode set to true.\e[0m" >&2
exit 1
fi
fi
done
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置pre-commit
Python 项目的存储库。运行后,pre-commit install
我看到这样的输出:
[INFO] Installing environment for https://github.com/asottile/seed-isort-config.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/mirrors-isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/mirrors-pylint.
[INFO] Once installed this environment will be reused. …
Run Code Online (Sandbox Code Playgroud) 我们希望在我们的git存储库中执行推送的每个人在完成之前运行"grunt".我们通过在具有推前钩执行本.git/hooks/pre-push
和写作npm install
,并grunt
在该文件中.
我们还有一个TFS存储库.我正在寻找在这里使用的类似逻辑.意思是,我们希望有一个排序的"门控签入"当有人试图检查的东西,这只会启动PowerShell和运行npm install
,并grunt
在本地.
我们不希望TFS做任何其他事情(运行构建,运行测试等等(所有这些都在grunt任务中完成)).
这可能吗?谁知道怎么样?
我们有一个特定的要求,我们必须将所有到达的文件推送到某个分支.
我们计划通过git hooks专门实现commit-msg hook来实现这一点.
在这样做的同时,我们将分支克隆到临时位置(/ tmp /),然后在git commit-msg钩子中,尝试将到达的文件提交到某个分支.
但现在发生的是我们在/ tmp /中看到所有文件都被删除了.
粗体commit-msg脚本如下: -
#!/bin/bash
#
#!/usr/bin/env bash
#git config credential.helper store
REPOSRC="https://<USER>:<PASS>@<REPO_URL>"
LOCALREPO="<LOCAL_REPO_DIR>"
echo "Pulling code to temporarry location";
cd /tmp && git clone "${REPOSRC}" || (cd "${LOCALREPO}"; git pull;)
#here when I navigate to /tmp/<LOCALREPO> all files are listed as DELETED
git diff --cached --name-status | while read st file; do
echo "file == $file and status == $st";
if [ "$st" == "A" ]; then
cd "${LOCALREPO}" && …
Run Code Online (Sandbox Code Playgroud) 我正在使用 GitKraken (不确定是否相关),当我尝试提交时,我收到以下错误消息:
当我按下“查看挂钩输出”按钮时,我得到以下信息:
预提交
husky > npm run -s 预提交(节点 v8.9.4)[?25l
npm > 运行 src/**/*.js 的任务
\ 纱线格式 git add (...这两行很多...)
\ 纱线格式 git add
“纱线格式”发现一些错误。请修复它们并再次尝试提交。纱线运行 v1.6.0 $ prettier-standard './src/**/*.js' C:\mypath\myfile.js info[访问 [0;1mhttps://yarnpkg.com/en/docs/cli/run有关此命令的文档。
prettier-eslint [错误] 由于 eslint 错误,eslint 修复失败 prettier-standard [错误] 格式化“C:\mypath\messages.js”时出现错误:TypeError:无法读取 null 属性“范围”
at SourceCode.getTokenBefore (c:\mypath\index.js:303:18)
at checkSpacingBefore (C:\mypath\template-curly-spacing.js:52:42)
at TemplateElement (C:\mypath\template-curly-spacing.js:117:17)
at listeners.(anonymous function).forEach.listener (C:\mypath\safe-emitter.js:47:58)
at Array.forEach (<anonymous>)
at Object.emit (C:\mypath\safe-emitter.js:47:38)
at NodeEventGenerator.applySelector (C:\mypath\node_modules\eslint\lib\utilode-event-generator.js:251:26)
at NodeEventGenerator.applySelectors (C:\mypath\node_modules\eslint\lib\util\node-event-generator.js:280:22)
at NodeEventGenerator.enterNode (C:\mypath\node-event-generator.js:294:14)
at CodePathAnalyzer.enterNode (C:\mypath\code-path-analyzer.js:608:23)
at Traverser.enter [as _enter] …
Run Code Online (Sandbox Code Playgroud) 我开始使用 Prettier + eslint 使用pretty-quick
& husky
(选项 2)。它的行为符合预期,即在提交(或修改)期间重新格式化代码并包含提交中的更改。
我的 monorepo 需要(几个)更多的预提交钩子,所以我最终迁移到pre-commit.com(选项 3)。现在,当我提交或修改时,Prettier 会修改文件并返回Failed
状态。这造成了一个相当烦人的工作流程,我被迫添加文件并尝试再次提交更改。
有什么方法可以将更改重新暂存为提交的一部分吗?