Git远程是否可能是计算机本身的一个位置,而不是网络位置



到目前为止,我已经看到git远程在网络上。它是否可能是计算机上的一个位置,就像另一个驱动器或另一个目录一样?如果是,如何?

https://git-scm.com/docs/git-pull#_git_urls

对于本地存储库,也由Git本地支持,可以使用以下语法:

/path/to/repo.git/
file:///path/to/repo.git/

是。对于本地存储库,远程可以是指向另一个本地文件夹的相对路径或绝对路径。此外,它可以是语法file:///path/to/folder。以下是关于遥控器的更多事实。

远程可以是git捆绑包,也可以是只读捆绑包。

git init /path/to/foo
cd /path/to/foo
touch a.txt
git add .
git commit -mfoo
git bundle create /path/to/foo.bundle master
git init /path/to/bar
cd /path/to/bar
git remote add origin /path/to/foo.bundle
# it's possible to fetch data from the bundle
git fetch origin master
git checkout master
# it's not possible to push data to the bundle
# git push fails

远程可以是存储库本身。

git init /path/to/foo
cd /path/to/foo
touch a.txt
git add .
git commit -mfoo
# add a remote which is the repository itself
git remote add origin .
# or
git remote add origin /path/to/foo
# push "master" to create a new branch "new_master"
git push origin master:new_master

远程存储库可以是可从当前存储库访问的任何存储库,即使这两个存储库完全不同。

git clone https://github.com/arobson/rabbot
cd rabbot
git remote add new https://github.com/fooplugins/FooTable
git fetch new

是的,使用Git是可能的。我经常用这种方法打球使用git pull/git push命令而无需使用网络

示例(你没有指定你使用的系统,所以我假设Unix(:

在/tmp/orig存储库中创建远程git存储库:

$ mkdir /tmp/orig-repository
$ cd /tmp/orig-repository
$ git init --bare
Initialized empty Git repository in /tmp/orig-repository/

在/tmp/Clone repository:中克隆新创建的存储库

$ mkdir /tmp/clone-repository
$ cd /tmp/clone-repository
$ git clone /tmp/orig-repository
Cloning into 'orig-repository'...
warning: You appear to have cloned an empty repository.
done.
$ cd orig-repository

制作测试文件并推送更改:

$ touch file
$ git add file
$ git commit -m 'add file'
[master (root-commit) 5f365e5] add file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 209 bytes | 209.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To /tmp/orig-repository
* [new branch]      master -> master

注意origin/master存在:

$ git branch -r
origin/master

您可以将/tmp/orig存储库克隆到文件系统,推送,然后在/tmp/clone存储库中执行git fetch,就像您使用了Github或任何远程Git服务器。

相关内容

最新更新