设置本地 git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19839996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting-up local git repository
提问by David B
I am a fan of using GitHubas my project file repository. But it interest me more if I am able to create a repository on this computer on a different directory path. Then clone that create repository on my new working directory.
我喜欢使用GitHub作为我的项目文件存储库。但如果我能够在这台计算机上的不同目录路径上创建一个存储库,我会更感兴趣。然后在我的新工作目录中克隆创建存储库。
I was planning to make a GitHublocally. I've been searching about this and many return that I should use gitoliteand many more instead. The problem I am using Windows and I want to do all the steps using command line.
我打算在本地制作一个GitHub。我一直在寻找这个问题,许多人返回说我应该使用gitolite等等。我使用的是 Windows 的问题,我想使用命令行完成所有步骤。
What command lines should I enter to create a repository on a different directory other than the working directory and be able to clone that repository to other terminals within the local network.
我应该输入哪些命令行来在工作目录以外的不同目录上创建存储库,并能够将该存储库克隆到本地网络中的其他终端。
LINKING TERMINAL to Windows Host
链接终端到 Windows 主机
I have created a repository directory pathed to Users\username\GIT\project.git
.
I am trying to link my terminal using the command line git clone file://{IPv4 server address}/Users/username/GIT/project.git
returns
我创建了一个路径为Users\username\GIT\project.git
. 我正在尝试使用命令行git clone file://{IPv4 server address}/Users/username/GIT/project.git
返回链接我的终端
fatal: '/{IPv4 server address}/Users/username/GIT/project.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
How can I resolve this? I my host is running on Windows 7 and my connecting terminal(s) will be using Ubuntu 12.04 LTS and MacOS Mavericks.
我该如何解决这个问题?我的主机在 Windows 7 上运行,我的连接终端将使用 Ubuntu 12.04 LTS 和 MacOS Mavericks。
UPDATE TRACK
更新轨迹
- Updated my question body. I don't know what steps should I follow.
- Inserted LINKING TERMINAL to Windows Hostquestion for repository sharing over local network.
- 更新了我的问题正文。我不知道我应该遵循哪些步骤。
- 将LINKING TERMINAL插入到 Windows 主机问题以通过本地网络共享存储库。
回答by Fwolf
Maybe you're asking simple way to create git repo and local clone ?
也许您在问创建 git repo 和 local clone 的简单方法?
- Create git repo using
git init --bare
- Clone from other place using
git clone --local /path/your/local/repo/
- 使用创建 git repo
git init --bare
- 使用从其他地方克隆
git clone --local /path/your/local/repo/
For local network, windows share or other file share may work.
对于本地网络,windows 共享或其他文件共享可能有效。
But, the simple way just work, not best or suitable way. there aren't pull request, issue track, privilege control feature on GitHub. For manage git commit or other complicated work, you need a manage system, such as gitolite, gerrit, some may not work on windows system.
但是,简单的方法只是有效,而不是最佳或合适的方法。GitHub 上没有拉取请求、问题跟踪、权限控制功能。管理 git commit 或其他复杂的工作,你需要一个管理系统,比如 gitolite,gerrit,有些在 windows 系统上可能不起作用。
If you only need a free private repo, you an use bitbucket.
如果你只需要一个免费的私人仓库,你可以使用 bitbucket。
Clone from windows share:
从 Windows 共享克隆:
git clone file:////{IPv4 server address}/share_name/path_to_your_.git_dir
On host computer, you must share repo dir with a 'share_name', eg: parent dir of repo.git
在主机上,您必须使用“share_name”共享 repo 目录,例如:repo.git 的父目录
See:
看:
回答by Litmus
If I read your problem statement correctly, You can simply clone a local git repo into another folder by using the --local
switch on the clone command like this
如果我正确阅读了您的问题陈述,您可以简单地使用--local
克隆命令上的开关将本地 git repo 克隆到另一个文件夹中,如下所示
git clone --local /git/source_repo/project /home/username/workdir/project
where
在哪里
/git/source_repo/project
is the safe copy of the repo (call it your personal GitHub
if you like).
/git/source_repo/project
是 repo 的安全副本(GitHub
如果您愿意,可以将其称为您的个人)。
and
和
/home/username/workdir/project
is your working folder. It can be any folder where you want to make frequent commits
/home/username/workdir/project
是您的工作文件夹。它可以是您想要频繁提交的任何文件夹
Switches explained:
开关说明:
--local
When the repository to clone from is on a local machine, this flag bypasses the normal "git aware" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories. The files under .git/objects/ directory are hardlinked to save space when possible.
If the repository is specified as a local path (e.g., /path/to/repo), this is the default, and --local is essentially a no-op. If the repository is specified as a URL, then this flag is ignored (and we never use the local optimizations). Specifying --no-local will override the default when /path/to/repo is given, using the regular git transport instead.
To force copying instead of hardlinking (which may be desirable if you are trying to make a back-up of your repository), but still avoid the usual "git aware" transport mechanism, --no-hardlinks can be used.
--no-hardlinks
Optimize the cloning process from a repository on a local filesystem by copying files under .git/objects directory.
- 当地的
当要克隆的存储库在本地机器上时,此标志绕过正常的“git 感知”传输机制,并通过复制 HEAD 以及对象和 refs 目录下的所有内容来克隆存储库。.git/objects/ 目录下的文件被硬链接以尽可能节省空间。
如果存储库被指定为本地路径(例如,/path/to/repo),这是默认值,而 --local 本质上是一个无操作。如果存储库指定为 URL,则忽略此标志(并且我们从不使用本地优化)。指定 --no-local 将在给出 /path/to/repo 时覆盖默认值,而是使用常规的 git 传输。
要强制复制而不是硬链接(如果您尝试备份存储库,这可能是可取的),但仍然避免通常的“git 感知”传输机制,可以使用 --no-hardlinks。
--无硬链接
通过复制 .git/objects 目录下的文件来优化从本地文件系统上的存储库的克隆过程。
see documentationfor more details
有关更多详细信息,请参阅文档
Update 1:
更新 1:
For setting up a Git Server on Windows, you can try this commercial
(open source) software called GitStack.
要在 Windows 上设置 Git 服务器,您可以尝试使用commercial
名为GitStack 的(开源)软件。
Useful GitStack resources:
有用的 GitStack 资源:
- GitStack Installation Instructions
- Link to source code of GitStack on Github
- GitStack安装说明
- 链接到Github上GitStack 的源代码
回答by Greg Gauthier
To create a local bare repository, the command is actually pretty simple:
要创建本地裸存储库,命令实际上非常简单:
git clone --bare my_project my_project.git
Initialized empty Git repository in /my/projects/my_project.git/
As long as you're using these locally (say, from a USB attached storage device or something), that's really all there is to it. You would just point your commands at that repo, for cloning, pushing, pulling, etc. Though, one might ask why you'd want to do such a thing.
只要您在本地使用这些(例如,从 USB 连接的存储设备或其他东西),这就是全部。您只需将您的命令指向该存储库,用于克隆、推、拉等。不过,有人可能会问您为什么要做这样的事情。
These instructions are for getting setup on a server, but I found these instructions really helpful for creating local repos as well: http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server
这些说明用于在服务器上进行设置,但我发现这些说明对于创建本地存储库也非常有用:http: //git-scm.com/book/en/Git-on-the-Server-Getting-Git-服务器上