Py学习  »  Git

git clone-如何确定目录[重复]

odd_duck • 4 年前 • 1137 次点击  

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

/httpdocs/whatever/public

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

/httpdocs/public

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

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46198
 
1137 次点击  
文章 [ 18 ]  |  最新文章 4 年前
Gene Bo
Reply   •   1 楼
Gene Bo    10 年前

关于这条线从原来的职位:

“我知道在克隆了repo之后如何移动文件,但是 好像要把它弄坏了“

我可以做到这一点,而且到目前为止,我的添加、提交、推送、拉取操作没有任何问题。

这种方法如上所述,但并没有分解成步骤。 以下是对我有效的步骤:

  1. 将repo克隆到任何新的临时文件夹中
  2. CD到刚才在本地克隆的根文件夹中
  3. 将文件夹的全部内容(包括./git目录)复制到您所喜欢的任何现有文件夹中(例如,您希望与您的回购协议合并的Eclipse项目)

刚刚复制文件的现有文件夹,现在准备好与Git进行交互。

Muhammad Awais
Reply   •   2 楼
Muhammad Awais    5 年前

我建议您遵循以下链接:

https://help.github.com/en/articles/cloning-a-repository

如果您在 Git克隆URL 命令

fatal: unable to access 'URL': Could not resolve host: github.com

然后使用以下命令修复它:

git config --global --unset https.proxy
Tarik
Reply   •   3 楼
Tarik    4 年前

尽管以上所有的答案都是好的,但是我想提出一种新的方法,而不是在公共html目录中使用符号链接方法,这是公认答案中最好的方法。您需要有权访问服务器虚拟主机配置。

它是关于配置直接指向存储库目录的web服务器的虚拟主机。在apache中,您可以这样做:

documentroot/var/www/html/website/your git repo

下面是虚拟主机文件的示例:

<VirtualHost *:443>
    ServerName example.com

    DocumentRoot /path/to/your-git-repo
    ...
    ...
    ...
    ...
</VirtualHost>
Tarit Ray
Reply   •   4 楼
Tarit Ray    5 年前
For Windows user 

1> Open command prompt.
2> Change the directory to destination folder (Where you want to store your project in local machine.)
3> Now go to project setting online(From where you want to clone)
4> Click on clone, and copy the clone command.
5> Now enter the same on cmd .

It will start cloning saving on the selected folder you given .
Ankit Singh
Reply   •   5 楼
Ankit Singh    7 年前

如果你正在使用 ssh 对于 git cloning 您可以使用以下命令。

git -C path clone git@github.com:path_to_repo.git

如: git -C /home/ubuntu/ clone git@github.com:kennethreitz/requests.git 会将git存储库 requests 对你 /home/ubuntu/ 路径。

prosti
Reply   •   6 楼
prosti    5 年前

由于某种原因,这种语法并不突出:

git clone repo-url [folder]

此处的文件夹是指向本地文件夹(将是本地存储库)的可选路径。

吉特 clone 也会 pull 从远程存储库到本地存储库的代码。 事实上这是真的:

git clone repo-url  =  git init + git remote add origin repo-url + git pull
Peter Mortensen Ev-
Reply   •   7 楼
Peter Mortensen Ev-    7 年前

我会这样做,但我已经化名为我做了。

$ cd ~Downloads/git; git clone https:git.foo/poo.git

可能有一种更优雅的方式来做这件事,但是我发现这对我自己来说是最简单的。

这是我为加快速度而创建的别名。我是为zsh做的,但是对于bash或者其他任何贝壳,比如鱼,xyzsh,fizsh,等等,它都应该很好用。

编辑 ~/.zshrc , /.bashrc 你最喜欢的编辑(我的是leafpad,所以我会写 $ leafpad ~/.zshrc )

不过,我个人的偏好是制作一个zsh插件来跟踪我的所有别名。您可以通过运行以下命令为Oh My zsh创建个人插件:

$ cd ~/.oh-my-zsh/
$ cd plugins/
$ mkdir your-aliases-folder-name; cd your-aliases-folder-name
     # In my case '~/.oh-my-zsh/plugins/ev-aliases/ev-aliases'
$ leafpad your-zsh-aliases.plugin.zsh
     # Again, in my case 'ev-aliases.plugin.zsh'

然后,将这些行添加到新创建的blank alises.plugin文件中:

# Git aliases
alias gc="cd ~/Downloads/git; git clone "

(从这里开始,用我的名字代替你的名字。)

然后,为了让别名起作用,它们(连同zsh)必须来源于(或它的名称)。为此,在自定义插件文档中添加以下内容:

## Ev's Aliases

#### Remember to re-source zsh after making any changes with these commands:

#### These commands should also work, assuming ev-aliases have already been sourced before:

allsource="source $ZSH/oh-my-zsh.sh ; source /home/ev/.oh-my-zsh/plugins/ev-aliases/ev-aliases.plugin.zsh; clear"
sourceall="source $ZSH/oh-my-zsh.sh ; source /home/ev/.oh-my-zsh/plugins/ev-aliases/ev-aliases.plugin.zsh"
#### 

####################################

# git aliases

alias gc="cd ~/Downloads/git; git clone "
# alias gc="git clone "
# alias gc="cd /your/git/folder/or/whatever; git clone "

####################################

保存你的Oh My zsh插件,然后运行 allsource . 如果看起来不管用,就跑 source $ZSH/oh-my-zsh.sh; source /home/ev/.oh-my-zsh/plugins/ev-aliases/ev-aliases.plugin.zsh . 它将加载插件源,允许您使用 所有来源 从现在开始。


我正在制作一个带有所有我的别名的Git存储库。请在这里随意查看: Ev's dot-files . 请随意挑选并改进以满足您的需要。

JJD alex
Reply   •   8 楼
JJD alex    10 年前

如果要将内容签出到当前目录中,请确保删除.git存储库。

rm -rf .git 然后 git clone https://github.com/symfony/symfony-sandbox.git

Peter Mortensen Ev-
Reply   •   9 楼
Peter Mortensen Ev-    7 年前

用法

git clone <repository>

将位于<repository>的存储库克隆到本地计算机上。原始存储库可以位于本地文件系统上,也可以位于通过HTTP或SSH访问的远程机器上。

git clone <repo> <directory>

将位于<repository>的存储库克隆到本地计算机上名为<directory>的文件夹中。

来源 Setting up a repository

Sarat Chandra
Reply   •   10 楼
Sarat Chandra    7 年前

克隆到 当前工作目录 :

Git克隆 https://github.com/link.git

克隆到 另一个目录 :

Git克隆 https://github.com/link.git网站 /文件夹1/文件夹2

希望有帮助:)

Peter Mortensen Ev-
Reply   •   11 楼
Peter Mortensen Ev-    7 年前

如果要克隆到当前文件夹中,应尝试以下操作:

git clone https://github.com/example/example.git ./
Geoffrey Hale Selvamani
Reply   •   12 楼
Geoffrey Hale Selvamani    7 年前

克隆:

git clone git@jittre.unfuddle.com:jittre/name.git

克隆“特定分支”:

git clone -b [branch-name] git@jittre.unfuddle.com:jittre/name.git
Paul
Reply   •   13 楼
Paul    15 年前

当您将文件移动到所需位置时,是否也将 .git 目录?根据您的操作系统和配置,此目录可能被隐藏。

它包含repo和支持文件,而 /public 目录只是当前签出提交中的版本(默认情况下是主分支)。

kenorb
Reply   •   14 楼
kenorb    4 年前

要将git存储库克隆到特定文件夹中,可以使用 -C <path> 参数,例如

git -C /httpdocs clone git@github.com:whatever

尽管它仍然会创造 whatever 文件夹,以便将存储库的内容克隆到当前目录中,请使用以下语法:

cd /httpdocs
git clone git@github.com:whatever .

请注意,克隆到现有目录是 只有 当目录为 空的 .

由于要克隆到可供公众访问的文件夹中,请考虑使用 --separate-git-dir=<git dir> 或排除 .git Web服务器配置中的文件夹(例如 .htaccess 文件)。

Craig Gjerdingen
Reply   •   15 楼
Craig Gjerdingen    5 年前

基本Git存储库克隆

使用克隆存储库

git clone [url]

例如,如果要克隆斯坦福大学drupal开放框架git库open_framework,可以这样做:

$ git clone git://github.com/SU-SWS/open_framework.git

它创建一个名为OpenByFrror的目录(在当前的本地文件系统位置),在其内部初始化.git目录,拉下该存储库的所有数据,并检查最新版本的工作副本。如果您进入新创建的open_framework目录,您将看到其中的项目文件,可以使用。

将存储库克隆到特定的本地文件夹中

如果要将存储库克隆到名为open_framework以外的目录中,可以将其指定为下一个命令行选项:

$ git clone git:github.com/SU-SWS/open_framework.git mynewtheme

该命令与前一个命令相同,但是目标目录被称为MyNeWestBeST。

git有许多不同的传输协议可以使用。前面的示例使用git://协议,但您也可以看到http(s):///或user@server:/path.git,它使用ssh传输协议。

Peter Mortensen Ev-
Reply   •   16 楼
Peter Mortensen Ev-    7 年前

进入文件夹..如果文件夹为空,则:

git clone git@github.com:whatever .

其他的

git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master
J Wynia
Reply   •   17 楼
J Wynia    14 年前

我想很多人问这个问题都是为了这个。如果你是 在里面 要将Git存储库的内容转储到的目录,运行:

git clone git@github.com:whatever .

结尾的“.”将当前文件夹指定为签出文件夹。

flindeberg Can Berk Güder
Reply   •   18 楼
flindeberg Can Berk Güder    4 年前

选项A:

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

埃尔戈 right here 用途:

git clone git@github.com:whatever .

选项B:

移动 .git 文件夹也是。请注意 Git 文件夹在大多数图形文件资源管理器中隐藏,因此请确保显示隐藏的文件。

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

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

更好的是:

把你的工作副本放在其他地方,并创建一个符号链接。这样地:

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

对你来说,可能是这样的:

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

如果你想要的话,可以很容易地更改为测试,即:

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

不移动文件。补充 -fn 万一有人抄这些行( -f 就是力量, -n 避免一些与现有和非现有链接不必要的交互。

如果你只是想让它工作,使用选项a,如果有人要看你做了什么,使用选项c。