[英]Getting a working copy of a bare repository
我有一台服务器,上面有一个用于推送的裸存储库。 但是,我的服务器需要有一个 master 分支的工作副本。
如何获取工作副本并且仅从裸存储库获取?
您可以简单地将存储库克隆到同一台机器上的另一个目录:
git clone /bare/repo/dir
当前目录将成为您的 repo 的非裸克隆,您将自动获得master
分支的检出。 然后使用像git pull
这样的常用命令根据需要更新它。
附带的好处是,这个操作非常有效——如果你为git clone
指定一个本地目录,git 将使用硬链接来共享两个 repos 的对象数据库的只读部分。
裸仓库只是工作目录的 .git 目录,以及本地配置文件中的一个条目。 我将裸存储库转换为完整存储库的操作是:
.git
并将裸存储库中的所有文件移动到那里.git/config
文件,将bare = true
更改为bare = false
您可以在 Windows 上的.git
目录上设置 Hidden 属性,但不能在目录内的文件上设置。
我一直在寻找的“沾边的工作树”的方法(如看到这里):
git init --bare
git config core.bare false
git config core.worktree /somewhere/else/
git checkout -f
这对我有用:
git --git-dir=path-to-bare-repo.git --work-tree=path-to-target checkout master .
此命令会将存储库中的所有文件提取到path-to-target
指定的目录中
这是对其他 2 个答案的即兴演奏,但它填补了我的用例的空白——它适用于从源更新 repo 并检查分支和任何 git 操作,因为你最终会得到一个正常的完整 git repo。
git clone /path/to/bare/repo /new/path/to/full/repo
cd /new/path/to/full/repo
git remote set-url origin git@github.com:swift/swift.git
执行这 3 行代码后,您可以git pull
和git branch
以及git checkout some_branch
等等,因为您现在有一个正常的完整 git repo 连接到您的远程 repo。
这是它的工作原理:
$ git init --separate-git-dir /path/to/existing-bare-repository /path/to/workdir
$ cd /path/to/workdir
$ git checkout .
瞧!
有关信息: git init
将报告: Reinitialized existing Git repository in /path/to/existing-bare-repository
。 但要自信。 man git-init
说:在现有存储库中运行 git init 是安全的。 它不会覆盖已经存在的东西。
神奇的是,单独的git init
不会使您的文件出现在工作目录中。 您必须签出根目录。
您可以为此使用“git show”。
http://www.kernel.org/pub/software/scm/git/docs/git-show.html
基本上:
git --no-pager --git-dir /path/to/bar/repo.git show branch:path/to/file.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.