Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

git - 如何将Git存储库克隆到特定文件夹?(How do you clone a Git repository into a specific folder?)

Executing the command git clone [email protected]:whatever creates a directory in my current folder named whatever, and drops the contents of the Git repository into that folder:

(git clone [email protected]:whatever执行git clone [email protected]:whatever命令git clone [email protected]:whatever都会在我当前的文件夹中创建一个名为any的目录,并将Git存储库的内容拖放到该文件夹??中:)

/httpdocs/whatever/public

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:

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

/httpdocs/public

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 .

(克隆存储库后,我知道如何移动文件,但这似乎破坏了Git,我希望仅通过调用git pull即可进行更新。)

How can I do this?

(我怎样才能做到这一点?)

  ask by David Smith translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Option A:

(选项A:)

git clone [email protected]:whatever folder-name

Ergo, for right here use:

(Ergo,在right here使用:)

git clone [email protected]:whatever .

Option B:

(选项B:)

Move the .git folder, too.

(也移动.git文件夹。)

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

(请注意, .git文件夹在大多数图形文件浏览器中都是隐藏的,因此请确保显示隐藏的文件。)

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

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 (ie shopt -s dotglob ) but that is probably a bad solution if you are asking the question this answer answers.

(也可以通过启用dotglob(即shopt -s dotglob )在一行中完成此操作,但是如果您问这个答案所回答的问题,那可能是一个不好的解决方案。)

Better yet:

(更好的是:)

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 you 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, ie:

(可以轻松更改以测试是否需要,即:)

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

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).

(添加了-fn ,以防有人复制这些行( -f是强制的, -n避免与已经存在或不存在的链接进行某些经常不必要的交互)。)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...