简体   繁体   English

使用Bash脚本克隆Git存储库

[英]Clone Git repo with Bash script

I'm diving into the world of Git and my first task is to automate our build process. 我正进入Git的世界,我的首要任务是使我们的构建过程自动化。 I'm using Bash since that's what I'm familiar with and it seems to do what I need. 我正在使用Bash,因为这是我所熟悉的,而且似乎可以满足我的需求。

Before I can build my code, I need to clone the latest version of the repo to my PC. 在生成代码之前,需要将最新版本的存储库克隆到PC上。

I seem to have a catch 22. I want to clone a repo from a Bash script that would be part of the repo I'm trying to clone. 我似乎有一个陷阱22.我想从一个Bash脚本克隆一个回购协议,该脚本将成为我要克隆的回购协议的一部分。

I want my build/bash script to be under source control along with everything else... But I'd also like a one command operation. 我希望我的build / bash脚本以及其他所有内容都受源代码控制。但是我也想执行一个命令操作。

How do others tackle this problem? 别人如何解决这个问题? I'm most familiar with ClearCase so Git is taking some getting used to. 我对ClearCase最为熟悉,因此Git逐渐习惯了。

Git clone is analogous to ClearCase mkview in that it creates a new working folder that serves as the main way to interact with files in the repository. Git clone类似于ClearCase mkview ,它创建了一个新的工作文件夹,该文件夹是与存储库中的文件进行交互的主要方式。 If you were writing this script for ClearCase, would you really start by having it create a new ClearCase view? 如果您正在为ClearCase编写此脚本,您是否真的会从创建一个新的ClearCase视图开始呢? If you did, you'd have the same catch-22 situation. 如果这样做的话,您将面临同样的22局情况。

The common approach is to assume that the clone operation was done as part of one-time setup of this build system, and the script already has access to the working folder. 通用方法是假定clone操作是此构建系统的一次性设置的一部分,并且脚本已经可以访问工作文件夹。 The Git commands you'd be more interested in are clean , checkout , fetch , pull , and reset --hard . 您可能更感兴趣的Git命令是cleancheckoutfetchpullreset --hard There's overlap between Git commands, so you won't need all of these. Git命令之间有重叠,因此您不需要所有这些。 Obviously the choice of Git commands and the options you'd call them with depends on what you want you want your script to do. 显然,Git命令的选择以及调用它们的选项取决于您希望脚本执行的操作。

Done that way, there's no problem keeping the script in the repository, except you will wind up versioning it in the same branch(es) as the code you're building. 这样,将脚本保留在存储库中就没有问题,除了您将在与要构建的代码相同的分支中完成版本控制。 This isn't necessarily bad, but is different from what would (usually) happen in ClearCase. 这并不一定很糟糕,但与ClearCase中通常发生的情况不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM