[英]What's the best way to avoid copy-pasting code in a GitHub Repo
First off let me apologize if this is a really dumb question, I'm fairly new to GitHub having never used any form of source control before :( 首先,如果这是一个愚蠢的问题,让我道歉,我是GitHub的新手,以前从未使用过任何形式的源代码控制:(
I have written a Powershell function (named Output-CORE) that I use quite a lot across a few of my scripts and at the moment I am copy-pasting this into the root directory of each of the scripts that end up using this function. 我已经编写了一个Powershell函数(名为Output-CORE),在我的一些脚本中使用了很多功能,此刻,我将其复制粘贴到每个最终使用此函数的脚本的根目录中。
This means anytime I update the Output-CORE function I have to edit every instance of it, which is getting tedious to say the least. 这意味着每当我更新Output-CORE函数时,我都必须编辑它的每个实例,这至少可以说是乏味的。
Is there a way I can have this function in one place in my repo and then have it symlinked or something to each of the directories? 有什么办法可以让我在仓库中的某个位置拥有此功能,然后将其符号链接到每个目录?
I've done some reading but I'm not sure if symlinks would work on our infrastructure (the code is written on Windows 10 machines and the repo is cloned onto our Windows Server 2012r2 SCCM management system where it is used as the basis of packages to be deployed to user systems). 我已经读了一些书,但不确定符号链接是否可以在我们的基础结构上正常工作(代码是在Windows 10计算机上编写的,并且存储库已克隆到我们的Windows Server 2012r2 SCCM管理系统中,在此系统中它用作软件包的基础)部署到用户系统)。
To give some clarity the structure of where Output-CORE lives in our GitHub: 为了更清楚地说明Output-CORE在我们的GitHub中的位置:
company-name\\ITScripts\\Output-CORE\\Output-CORE.ps1
and when it ends up copied into various folders it may look like: 当最终将其复制到各个文件夹中时,它可能类似于:
company-name\\ITScripts\\SCCM\\[script folder name]\\[dependencies folder]\\Output-CORE.ps1
Any pointers would be greatly appreciated. 任何指针将不胜感激。 :)
:)
Managed to solve this with a tiny amount of faff. 设法用很少的麻烦解决了这个问题。 I made symlinks relative to the repo on my windows machine:
我在Windows机器上做了相对于仓库的符号链接:
mklink /D company-name\\ITScripts\\SCCM\\[script folder name]\\Output-CORE ..\\..\\Output-CORE
which then means everything gets copied over to SCCM for distribution and I only have to edit the script in one place going forward. 这意味着所有内容都将复制到SCCM进行分发,而我只需要在一个地方编辑脚本即可。
You learn something new everyday :D 你每天都学到新的东西:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.