git Git的离线使用

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

Offline use of Git

git

提问by Zeeshan Ali

How can we use git offline if we have many files and do not have an internet connection? Or can we store our files in just a committed state? And does git have capacity to store files? If yes, then how much?

如果我们有很多文件并且没有互联网连接,我们如何离线使用 git?或者我们可以将我们的文件存储在提交状态吗?git有存储文件的能力吗?如果是,那么多少钱?

采纳答案by abstractx1

If you want to use git offline just install git, go to the root directory for your files and run git initto initialize the repository. You can then run git add file_path, git commit -m "First commit"etc.

如果您想离线使用 git,只需安装 git,转到文件的根目录并运行git init以初始化存储库。然后你可以运行git add file_pathgit commit -m "First commit"等等。

The repository is stored under the .gitdirectory that is created under the directory in which you run git init.

存储库存储在.git您运行的目录下创建的目录下git init

回答by axiac

By design, Git keeps the entire project history in each clone of the repository. Most of its operations do not need a network connection.

按照设计,Git 将整个项目历史记录保存在存储库的每个克隆中。它的大部分操作不需要网络连接。

It needs a network connection only when you want to synchronize your clone with another clone located on a different computer. For example, when you want to make your changes available to your co-workers or get their contributions.

仅当您希望将您的克隆与位于不同计算机上的另一个克隆同步时,它才需要网络连接。例如,当您希望将您的更改提供给您的同事或获得他们的贡献时。

Read moreabout this item or, better, read the entire Git bookto learn how it works.

阅读有关此项目的更多信息,或者更好地阅读整本Git 书籍以了解其工作原理。

As a side note, if you work alone on a project Git doesn't need a network connection at all. It is, however, recommended to keep a clone of your repository (and synchronize it often) on a different computer (on GitHub, for example) for backup reasons.

附带说明一下,如果您单独处理一个项目,Git 根本不需要网络连接。但是,出于备份原因,建议将存储库的克隆(并经常同步)保存在不同的计算机上(例如在 GitHub 上)。

回答by Code-Apprentice

Yes, you can use Git offline. Git only requires an Internet connection when you use commands such as git remote, git pull, and git pushwith a remote repository that is stored on an Internet server. Any other commands that do not interact with a remote repository, such as git add, git commit, and git logto name a few, do not require any network connection. They modify files directly on your local machine in a subdirectory named .git. The size of this .gitsubdirectory is only limited by the physical capacity of the storage medium (typically a hard drive) where you save it.

是的,您可以离线使用 Git。Git 仅在您使用诸如git remotegit pull、 和git push存储在 Internet 服务器上的远程存储库等命令时才需要 Internet 连接。任何其他命令是不相互作用与远程存储库,比如git addgit commitgit log仅举几例,不需要任何网络连接。它们直接在您的本地计算机上的名为.git. 此.git子目录的大小仅受保存它的存储介质(通常是硬盘驱动器)的物理容量的限制。

To learn more about these commands, I suggest that you read Pro Git. This book is available for free online. The first three chapters teach you 99% of what you need for day-to-day use.

要了解有关这些命令的更多信息,我建议您阅读Pro Git。这本书可以在网上免费获得。前三章教您 99% 的日常使用所需。

Note that Git is separate from GitHub. Since GitHub is a bunch of servers connected to the Internet, you need a Internet connection to use it. When you use GitHub you will use the commands that I listed earlier because your remote repository will be on a GitHub server.

请注意,Git 与 GitHub 是分开的。由于 GitHub 是一堆连接到 Internet 的服务器,因此您需要 Internet 连接才能使用它。当您使用 GitHub 时,您将使用我之前列出的命令,因为您的远程存储库将位于 GitHub 服务器上。

回答by SandRock

This articlewill give you offline scenarios to work with. Copying the .gitfolder is a simplistic approach and more tooling exists within git.

本文将为您提供可使用的离线场景。复制.git文件夹是一种简单的方法,并且 git 中存在更多工具。

You can use the git bundlecommand to export and clone repos using a single file.

您可以使用该git bundle命令使用单个文件导出和克隆存储库。

; first export
PC1 $ git bundle create repoName.bundle --all
; and clone
PC2 $ git clone /path/to/repoName.bundle

; after a few commits, export again
PC1 $ git bundle create repoName.bundle --all
; and pull
PC2 $ git pull /path/to/repoName.bundle