doubi7306 2018-01-31 08:55
浏览 80
已采纳

通过项目同步PHP文件

I have a php server with this file tree :

/common
    - functions.inc.php
    - ...
/website1
    /functions
        - functions.inc.php
/website2
    /functions
        - functions.inc.php

Websites should be shipped separately without the common folder which might contain non-needed files per case (jquery extensions,...)

I would like to synchronize some files in common through all the website* projects, so for example when I change something in common/functions.inc.php the file is replaced in all the website*/functions/ folders

I am thinking of a bash script to do this (manual or through inotify), but I was wondering is there an automatic/manual native or an existing tool through version control (git, svn,...) to synchronize these files this way?

I have in mind something like the versioning of angular dependencies or maven depencies using a version number.

I am currently using an external svn (https://www.assembla.com/home), but if git has more options for this case I could consider migrating. My projects are on a linux machine (Raspberry pi or Lubuntu) but a Windows approach could be handy.

I completely own the functions.inc.php file so I can write anything inside such as a version number

  • 写回答

2条回答 默认 最新

  • douhui8025 2018-02-02 01:51
    关注

    Yes, you can use git pre-commit hook to sync common/functions.inc.php file with website*/functions/functions.inc.php files authmatically.

    Assume all the files of the file tree managed in master, then below sheel scripts for per-commit hook will detect if the common/functions.inc.php file changes, if changes, update website*/functions/functions.inc.php files before committing changes:

    #!/bin/sh
    #
    
    branch=$(git rev-parse --abbrev-ref HEAD)
    if [[ $branch == "master" ]]; then
      {
        echo "this is master branch"
        file="common/functions.inc.php"
        if [[ $(git diff --name-only HEAD) =~ $file ]]; then
          echo "changed the file"
          cp -fr common/functions.inc.php website1/functions
          cp -fr common/functions.inc.php website2/functions
        else
          echo "didn't change the file $(git diff --name-only HEAD)"
        fi
      }
    else
      echo "it's not on master branch"
    fi
    git add .
    

    And if you want to ship the code except the commom folder, then you can create a new branch (such as release), and then ignore the common folder:

    git checkout -b release
    rm -rf common
    touch .gitignore
    echo common >> '.gitignore'
    git add .
    git commit -m 'ignore common folder in release branch'
    

    And when your code is changed (in website* folder), you can update the release branch for a new shipment:

    git checkout release
    git checkout master -- website1/
    git checkout master -- website2/
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog