简体   繁体   English

如何“连接”一个 git 存储库而不先克隆它?

[英]How to "connect" a git repository without cloning it first?

I got a git repo on bitbucket that was used a few months ago for a php application.我在几个月前用于 php 应用程序的 bitbucket 上有一个 git repo。

I now have a new server and I would like to connect the local folder of this app on that repository.我现在有一个新服务器,我想连接该存储库上此应用程序的本地文件夹。 Challenge for me is that the local version is now more up to date than the bitbucket version.对我来说挑战是本地版本现在比 bitbucket 版本更新。 I'm newbie on git, and instructions I find always imply that we first clone the repo.我是 git 的新手,我发现的说明总是暗示我们首先克隆 repo。 I do not want to overwrite the local files first.我不想先覆盖本地文件。

I think you want to add or change a remote.我认为您想添加或更改遥控器。 To change the default remote use git remote set-url origin <url> or to add a new remote use git remote add要更改默认远程使用git remote set-url origin <url>或添加新远程使用git remote add

Instead of:代替:

git clone {remote-url} .

Directory Without Git Repo没有 Git 存储库的目录

If you don't already have a repo in the directory you're working in then this approach will work:如果您正在工作的目录中还没有repo,那么这种方法将起作用:

git init
git remote add origin {remote-url}

Directory With Existing Git Repo包含现有 Git 存储库的目录

If you do already have a repo in the directory you're working in:如果已经在你的工作目录中的回购:

git remote update origin {remote-url}

Now you have a repository that has been cloned, but is connected to your remote origin.现在您有一个已克隆的存储库,但已连接到您的远程源。

If you have a local (non-git revisioned) directory of some files and a git repository of the same project and you wish to update the git repository with the contents of the local files then you need to clone the repository into its own directory then manually copy all the local files on top of the cloned directory and then add, commit and push the new contents/changes to the remote git server.如果您有一些文件的本地(非 git 修订版)目录和同一项目的 git 存储库,并且您希望使用本地文件的内容更新 git 存储库,那么您需要将存储库克隆到自己的目录中,然后手动复制克隆目录顶部的所有本地文件,然后添加、提交并将新内容/更改推送到远程 git 服务器。

$ git clone https://name@bitbucket.org/name/name.git
# If the directory structures are identical then you might be able to do this with a single `cp`.
$ cp -r /path/to/local/code/* name
$ cd name
$ git status
# will show all the changed files, added files, etc.

then you get to use normal git operations to add and commit your changes and then push them all when you are done.然后你可以使用普通的 git 操作来添加和提交你的更改,然后在完成后将它们全部推送。 You can mass-add and commit the changes if you want one big "updated stuff" commit but I would strongly recommend avoiding that if at all possible (to keep the repository history at least marginally sane and understandable) in which case you get to create atomic commits out of pieces of the changes with git add -p , etc. .如果你想要一个大的“更新的东西”提交,你可以批量添加和提交更改,但我强烈建议尽可能避免这种情况(保持存储库历史至少稍微理智和可理解),在这种情况下你可以创建使用git add -p等更改原子提交。

Connect remote repository to local source:将远程存储库连接到本地源:

git init
git remote add origin {remote-repository-url}

To change the repository:要更改存储库:

git remote set-url origin {remote-repository-url}

Without any Git init or clone you can do this:没有任何 Git init 或 clone 你可以这样做:

git ls-remote [url] 

Here is your output:这是您的输出:

5fe978a5381f1fbad26a80e682ddd2a401966740    refs/heads/master
d6602ec5194c87b0fc87103ca4d67251c76f233a    refs/tags/v0.99

see more here Git Documentation git ls-remote在这里查看更多Git 文档 git ls-remote

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

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