如何跨文件夹或存储库共享文件


google你他吗
2025-03-18 08:47:49 (21天前)


我正在编写一个代码片段,它必须跨多个主题。

假设我有三个主题:
橙子
绿色
蓝色
每个主题都有一个名为“snippets”的文件夹,我把我的代码片段…

4 条回复
  1. 0# v-star*위위 | 2019-08-31 10-32



    也许您可以使用bash脚本在您的回购中自动执行此过程。以下脚本将获取您在第一个变量中设置的所有文件路径,并找到最后修改的路径。从那里它将该文件复制到其他所有文件,将它们添加到repo,然后提交。



    1.   #!/usr/bin/env bash
    2. declare -a filePaths=(“Orange/snippets/code.html Green/snippets/code.html Blue/snippets/code.html”)
      declare newestFile

    3. for file in ${filePaths[@]}”; do
      echo current file is $file
      if [[ $file -nt ${newestFile} ]];
      then
      newestFile=”${file}”
      fi
      echo newest file is ${newestFile}”
      done

    4. for file in ${filePaths[@]}”; do
      if ! [[ $file -ef $newestFile ]];
      then
      echo copying ${newestFile} to ${file}”
      cp ${newestFile} ${file}
      currentDir=dirname "${file}"
      cd ${currentDir}
      git add ${file}
      git commit -m automatic update commit
      fi
      done

    5. </code>


    修改code.hmtl文件后,您可以运行此脚本或使其成为生产管道的一部分。


  2. 1# 荧惑 | 2019-08-31 10-32



    像上面列出的那样的Php文件结构可以工作。片段文件夹本质上是一个.php扩展文件,其中包含项目之间或案例主题中的共享html文件。


  3. 2# Just do it | 2019-08-31 10-32



    假设您在存储库中有公共代码。
    你可以在里面创建一个子模块

    /snippets/common

    。每次要构建/部署主题时,请将其更新为最新的主数据库。



    这意味着你的

    code.html

    将在

    /snippets/common/code.html




    1. cd /snippets

    2. To add the submodule

      git submodule add common

    3. 2 new files will be added to the repository

      .gitmodules and the common folder

      When you clone the repo in another machine

      Always do the following command

      to get the files from the common repository

      git submodule update init

    4. If you made a change in the common repository

      git submodule update remote

    5. </code>

登录 后才能参与评论