Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Git存储库克隆到特定文件夹中?_Git_Repository_Git Clone - Fatal编程技术网

如何将Git存储库克隆到特定文件夹中?

如何将Git存储库克隆到特定文件夹中?,git,repository,git-clone,Git,Repository,Git Clone,执行命令git clonegit@github.com:which在我当前的文件夹中创建一个名为which的目录,并将Git存储库的内容放到该文件夹中: /httpdocs/whatever/public 我的问题是,我需要将Git存储库的内容克隆到当前目录中,以便它们显示在web服务器的正确位置: /httpdocs/public 我知道在克隆存储库后如何移动文件,但这似乎破坏了Git,我希望能够通过调用Git pull进行更新。我该怎么做?选项A: git clone git@githu

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

/httpdocs/whatever/public
我的问题是,我需要将Git存储库的内容克隆到当前目录中,以便它们显示在web服务器的正确位置:

/httpdocs/public

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

选项A:

git clone git@github.com:whatever folder-name
因此,对于此处的
使用:

git clone git@github.com:whatever .
选项B:

git clone git@github.com:whatever folder-name
也移动
.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
)在一行中完成,但如果您问的是这个答案所回答的问题,那么这可能是一个糟糕的解决方案

更好:

git clone git@github.com:whatever folder-name
将工作副本保存在其他地方,并创建一个符号链接。像这样:

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。

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


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

我想很多人都在问这个问题。如果您位于希望将git存储库的内容转储到的目录中,请运行:

git clone git@github.com:whatever .
git clone git@github.com:origin .

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

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

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

克隆:

git clone git@jittre.unfuddle.com:jittre/name.git
克隆“特定分支”:

基本Git存储库克隆 您可以使用

git clone [url]
例如,如果您想克隆斯坦福大学Drupal开放框架Git库Open_Framework,您可以这样做:

$ git clone git://github.com/SU-SWS/open_framework.git
这将创建一个名为open_framework的目录(在您当前的本地文件系统位置),初始化其中的.git目录,提取该存储库的所有数据,并签出最新版本的工作副本。如果您进入新创建的open_framework目录,您将看到其中的项目文件,可以处理或使用

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

$ git clone git:github.com/SU-SWS/open_framework.git mynewtheme
该命令的作用与前一个命令相同,但目标目录称为mynewtheme


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

关于原始帖子中的这一行:

“克隆回购协议后,我知道如何移动文件,但是 似乎打破了git“

我能够做到这一点,而且到目前为止,我没有发现添加、提交、推送和拉送操作存在任何问题

这种方法如上所述,只是没有细分为步骤。 以下是对我有用的步骤:

  • 将回购克隆到任何新的临时文件夹中
  • cd到您刚刚在本地克隆的根文件夹中
  • 将文件夹的全部内容(包括/.git目录)复制到您喜欢的任何现有文件夹中;(假设您希望与回购协议合并的eclipse项目)

  • 您刚刚将文件复制到的现有文件夹现在已准备好与git交互。

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

    git clone git@github.com:whatever .
    
    否则

    用法

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

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


    来源:

    以下是我的做法,但我已经为自己制作了一个别名

    $ cd ~Downloads/git; git clone https:git.foo/poo.git
    
    也许有一种更优雅的方法可以做到这一点,但是我发现这对我自己来说是最简单的

    这是我为加快进度而创建的别名。我为zsh制作了它,但它应该可以很好地用于bash或任何其他shell,如fish、xyzh、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'
    
    之后,将这些行添加到新创建的空白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
    。如果那样的话
    git -C /httpdocs clone git@github.com:whatever
    
    cd /httpdocs
    git clone git@github.com:whatever .
    
    git clone https://github.com/link.git
    
    git clone https://github.com/link.git ./Folder1/Folder2
    
    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 .
    
    git clone repo-url  =  git init + git remote add origin repo-url + git pull
    
    <VirtualHost *:443>
        ServerName example.com
    
        DocumentRoot /path/to/your-git-repo
        ...
        ...
        ...
        ...
    </VirtualHost>
    
    git clone <git_repo_url> <your_custom_directory_name>
    
    git clone git@github.com:origin .