如何在git中获取或拉取命令后立即执行命令? [英] How to execute a command right after a fetch or pull command in git?

查看:127
本文介绍了如何在git中获取或拉取命令后立即执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了GHC(格拉斯哥Haskell编译器)存储库。为了构建编译器,你需要几个库,它们也都可以用作git库。为了让人们生活得更轻松,GHC黑客们包括一个脚本 sync-all ,这些脚本在执行时会更新所有依赖的存储库。



现在我的问题:我做了一个 git pull ./ sync-all pull c $ c>自动?我听到有关使用钩子的一些信息,但我不知道,我必须做什么。

解决方案

post-receive post-update 钩子通常用于这种类型的任务,每次推后执行。

post-receive post-update 钩子在参数中:a post-receive 会同时得到旧的和



缺失的部分是:钩子在哪里执行自己?



博文 (很棒的)SO贡献者 Mark Longair 对此有一些阐述:


当前工作目录将是git目录


  • 因此,如果这是一个名为 /src/git/test.git / ,那将是当前工作目录
    - 如果这是一个非裸仓库,并且工作树的顶层是 / home / mark / test / ,那么当前的工作目录将是 /home/mark/test/.git /

>

Chris Johnsen 详细信息在他的 SO答案:如果 - git-dir GIT_DIR 但没有任何 - 工作树 GIT_WORK_TREE core.worktree 被指定时,当前工作目录被视为工作树的顶层目录。



换句话说,您的工作树也将是当前目录( .git 目录),几乎肯定不是你想要的


确保您的 hook / post-receive 脚本,一旦创建并可执行,就在正确的路径上设置 GIT_WORK_TREE code> ./ sync-all pull 要在正确的目录中执行(即不是 xxx.git 一个)。


I cloned the GHC (Glasgow Haskell Compiler) repository. In order to build the compiler, you need several libraries, all of them are available as git repositories too. In order to ease ones live, the GHC hackers included a script sync-all that, when executed, updates all the dependent repositories.

Now to my question: How can I make git execute ./sync-all pull after I did a git pull automatically? I heard something about using hooks, but I don't really know, what I have to do.

解决方案

A post-receive or post-update hook is generally used for this kind of task, executed after each push.
The difference between the post-receive and post-update hooks is in the arguments: a post-receive will get both the old and the new values of all the refs in addition to their names.

The missing piece is: where that hook executes itself?

The blog post "Missing git hooks documentation" from (a great) SO contributor Mark Longair sheds some light on this:

the current working directory will be the git directory.

  • So, if this is a bare repository called "/src/git/test.git/", that will be the current working directory – if this is a non-bare repository and the top level of the working tree is "/home/mark/test/" then the current working directory will be "/home/mark/test/.git/"

Chris Johnsen details in his SO answer: "If –-git-dir or GIT_DIR are specified but none of -–work-tree, GIT_WORK_TREE and core.worktree is specified, the current working directory is regarded as the top directory of your working tree."

In other words, your working tree will also be the current directory (the ".git" directory), which almost certainly isn’t what you want.

Make sure your hook/post-receive script, once created and made executable, sets the GIT_WORK_TREE at the right path, in order for your ./sync-all pull to be executed in the right directory (i.e. not "xxx.git" one).

这篇关于如何在git中获取或拉取命令后立即执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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