在本地机器上设置 git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5412562/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:26:45  来源:igfitidea点击:

setting up git repository on local machine

gitgit-workflow

提问by brainydexter

How can I setup a git repository on a local system ? (I am on a windoze box)

如何在本地系统上设置 git 存储库?(我在窗台上)

This is the setup I am trying to achieve: (everything is on my local machine)

这是我想要实现的设置:(一切都在我的本地机器上)

  • host folder (which acts like central repository)
  • client folder
  • 主机文件夹(就像中央存储库一样)
  • 客户文件夹

I want to do all my dev in the client folder. Once I am done, I'd like to push it to the host folder.

我想在客户端文件夹中完成我所有的开发。完成后,我想将其推送到主机文件夹。



This is what I've done: (using git bash on windows)

这就是我所做的:(在 Windows 上使用 git bash)

  • cd d:/adinsert
  • mkdir host
    • cd host
    • git init
  • cd d:/adinsert
  • mkdir 主机
    • 光盘主机
    • git初始化

cd c:/

CDC:/

  • mkdir client
    • cd client
    • git init
    • git remote add origin d:/host // Added some files in client folder and commited them
    • git push origin master
  • mkdir 客户端
    • 光盘客户端
    • git初始化
    • git remote add origin d:/host // 在客户端文件夹中添加一些文件并提交
    • git push origin master

When I push stuff to origin, git spits a lot of remote errors. However, when I make my host a bare git, it pushes successfully.

当我将东西推送到原点时,git 会吐出很多远程错误。但是,当我使我的主机成为裸 git 时,它会成功推送。

I don't understand the difference between regular git and bare git. From the manual, all I understood was, bare git is used for storing deltas and when you don't want to store original files. However, I'd like to store the files in host. How can I do that ?

我不明白普通 git 和裸 git 之间的区别。从手册中,我所理解的是,裸 git 用于存储增量以及当您不想存储原始文件时。但是,我想将文件存储在主机中。我怎样才能做到这一点 ?

采纳答案by Greg Hewgill

The difference between a "regular git" and a "bare git" is that a bare repository does nothave a working directory. You should never push into a regular git repository, as you may run into problems that are hard to recover from. Always push into a bare repository.

“定期混帐”和“裸混帐”之间的区别在于,一个纯仓库并不能有一个工作目录。您永远不应该推送到常规的 git 存储库,因为您可能会遇到难以从中恢复的问题。始终推送到裸存储库中。

If you want to have a "host" where copies of your files do appear, then set up a third repository, cloning from the host one. Whenever you want to update the host files:

如果你想要一个“主机”,你的文件副本确实出现,那么设置第三个存储库,从主机克隆。每当您想要更新主机文件时:

  • git pushfrom your working directory to update the main repository
  • git pullfrom your host directory to pull from the origin
  • git push从您的工作目录更新主存储库
  • git pull从您的主机目录中拉取源

You can even set up a post-commit hook on the bare repository to automatically do the second step.

你甚至可以在裸仓库上设置一个 post-commit 钩子来自动执行第二步。

回答by RDL

In your clientdirectory you have will notice a .gitdirectory. A bareversion is basically just that .gitdirectory contents without a working copy.

在您的client目录中,您会注意到一个.git目录。一个bare版本基本上只是.git没有工作拷贝目录内容。

Easiest thing to do would be to clone it (vs trying to setup another repository):

最简单的方法是克隆它(与尝试设置另一个存储库相比):

From c:/ call:

从 c:/ 调用:

git clone d:/host client

This says clone the 'host' repo and store it under a folder called 'client'.

这表示克隆“主机”存储库并将其存储在名为“客户端”的文件夹下。

回答by Kristian

Don't create a new git repo in the client folder, clone the host repo

不要在客户端文件夹中创建新的 git repo,克隆主机 repo

cd client
git clone d:/adinsert/host