sách gpt4 ăn đã đi

Git:如何通过更新 githook 将提交 merge 到分支中

In lại 作者:太空狗 更新时间:2023-10-29 14:23:03 25 4
mua khóa gpt4 giày nike

我正在做一个相当有趣的项目,试图做以下事情:

Whenever a developer pushes a commit to a remote branch, execute a githook that will lookup its associated QA branch via an issue tracking system, then merge that commit into the QA branch.

It's important that the commit to the remote branch (mirroring the developer's local branch) be rejected if there are any conflicts on the QA branch.

我遇到的问题是 git-merge(以及 pull、checkout 等)必须在工作树中运行,这会导致 githook 失败。

是否有一种(相对)简单的方法通过 cập nhật githook 将一个分支(或提交) merge 到另一个分支?我的理由是, Remote 虽然不是工作树,但显然具有执行此操作所需的所有数据,只是没有命令(据我所知)。

如果没有直接的命令,我的下一个想法是创建一个远程的临时克隆,我可以在其中执行 merge 操作:

(psuedocode)
mkdir $GIT_DIR/tempRepo
cd $GIT_DIR/tempRepo
git clone -b $QA_BRANCH --local $PARENT_DIR $CURRENT_DIR
git merge $WHATEVER
#cleanup

如果其中任何部分失败,我拒绝gia hạn(希望向开发人员提供一些有用的信息,以便他/她可以修复它)。我玩过这个解决方案,虽然它通过我的脚本看起来工作正常,但在真正的 Remote 上运行时它失败了(我还不知道为什么,但是在输入这个时,这个答案 pop 可能有帮助 - getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo )

我希望能从附近的 git 大师那里得到任何见解,我对支撑整个系统的管道还是相当陌生,所以如果我在正确(或错误)的轨道上,或者如果有一些我应该知道的魔法命令或陷阱,我将不胜感激。

Cảm ơn trước!

câu trả lời hay nhất

cập nhật Hook 是一个 server-side one ,这意味着它打算在工作树中工作,因为您通常 push to a bare repository .

您的场景更适合 CI 工具,例如 Jenkins (hoặc any othersTeamCityTravis-CICICircle 等...)

您可以设置 Jenkins 作业来检测分支上的任何新提交,如所述 in this answer .
Jenkins 作业(带有 JENKINS Git Plugin )将克隆 repo 并制作一个工作树,然后可以执行您想要的任何操作(并编写脚本),包括 merge 。

关于Git:如何通过更新 githook 将提交 merge 到分支中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32872785/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress