如何将 Git 存储库克隆到特定文件夹中? [英] How do you clone a Git repository into a specific folder?

查看:43
本文介绍了如何将 Git 存储库克隆到特定文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行命令 git clone git@github.com:whatever 在我当前的文件夹中创建一个名为 whatever 的目录,并将 Git 存储库的内容放入该文件夹中:

Executing the command git clone git@github.com:whatever creates a directory in my current folder named whatever, and drops the contents of the Git repository into that folder:

/httpdocs/whatever/public

我的问题是我需要将 Git 存储库的内容克隆到我的当前目录中,以便它们出现在 Web 服务器的正确位置:

My problem is that I need the contents of the Git repository cloned into my current directory so that they appear in the proper location for the web server:

/httpdocs/public

我知道在克隆存储库后如何移动文件,但这似乎破坏了 Git,我希望能够仅通过调用 git pull 进行更新.我该怎么做?

I know how to move the files after I've cloned the repository, but this seems to break Git, and I'd like to be able to update just by calling git pull. How can I do this?

推荐答案

选项 A:

git clone git@github.com:whatever folder-name

因此,对于就在此处使用:

git clone git@github.com:whatever .

选项 B:

也移动 .git 文件夹.请注意,.git 文件夹在大多数图形文件浏览器中是隐藏的,因此请务必显示隐藏文件.

Move the .git folder, too. Note that the .git folder is hidden in most graphical file explorers, so be sure to show hidden files.

mv /where/it/is/right/now/* /where/I/want/it/
mv /where/it/is/right/now/.* /where/I/want/it/

第一行抓取所有普通文件,第二行抓取点文件.也可以通过启用 dotglob(即 shopt -s dotglob)在一行中完成,但如果您问这个答案回答的问题,这可能是一个糟糕的解决方案.

The first line grabs all normal files, the second line grabs dot-files. It is also possibe to do it in one line by enabling dotglob (i.e. shopt -s dotglob) but that is probably a bad solution if you are asking the question this answer answers.

更好:

将您的工作副本保存在其他地方,并创建一个符号链接.像这样:

Keep your working copy somewhere else, and create a symbolic link. Like this:

ln -s /where/it/is/right/now /the/path/I/want/to/use

对于您的情况,这将类似于:

For your case this would be something like:

ln -sfn /opt/projectA/prod/public /httpdocs/public

如果您愿意,可以轻松更改以进行测试,即:

Which easily could be changed to test if you wanted it, i.e.:

ln -sfn /opt/projectA/test/public /httpdocs/public

无需移动文件.添加了 -fn 以防有人复制这些行(-f 是强制的,-n 避免与已经存在和不存在的一些经常不需要的交互链接).

without moving files around. Added -fn in case someone is copying these lines (-f is force, -n avoid some often unwanted interactions with already and non-existing links).

如果您只是想让它起作用,请使用选项 A,如果其他人要查看您所做的工作,请使用选项 C.

If you just want it to work, use Option A, if someone else is going to look at what you have done, use Option C.

这篇关于如何将 Git 存储库克隆到特定文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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