使用 U 盘上的 GIT 进行“旅行代码”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6389894/
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
Using GIT on USB stick for "travelling code"
提问by bovineone
I have exhaustively searched for answers to my question here and on Google. I have found some great resources and learning tools for understanding Git and what it does, but I need to get some clarification, and assistance.
我已经在这里和谷歌上详尽地搜索了我的问题的答案。我找到了一些很好的资源和学习工具来理解 Git 及其功能,但我需要一些说明和帮助。
What I am doing is working on a side-project for work both at my office and at home. (I'm migrating C# code to Java to help me learn both languages.)
我正在做的是在我的办公室和家里工作的副项目。(我正在将 C# 代码迁移到 Java 以帮助我学习这两种语言。)
The setup:
设置:
- Environment: Windows 7 (VS 2008 is on an XP virtual machine)
- Git: msysgit 1.7.4
- IDEs: VS 2008 and Eclipse
- Git plugins:
- Eclipse: I am using EGit.
- VS 2008: I plan on using one mentioned here on SO, Git Extensions
- Git repository: Located in \Repo on the USB stick - right now it just has a portion of the Java code as I fumble my way through learning Git.
- C# code in a Virtual Machine with VS 2008 that gets copied out of the VM to the USB stick - this is not under version control, yet.
- And yes, I have backup copies of all code for the "baseline". I had to since EGit, when you put the code under source control, moves it from my Eclipse workspace into the git repository on the USB drive. So if something goes crazy while learning, I can easily recover. I have not made major changes yet to the code, since I am still learning.
- 环境:Windows 7(VS 2008在XP虚拟机上)
- Git:msysgit 1.7.4
- IDE:VS 2008 和 Eclipse
- Git插件:
- Eclipse:我正在使用 EGit。
- VS 2008:我计划使用这里提到的 SO,Git Extensions
- Git 存储库:位于 U 盘上的 \Repo - 现在它只有一部分 Java 代码,因为我在学习 Git 的过程中摸索着。
- 带有 VS 2008 的虚拟机中的 C# 代码从 VM 复制到 USB 记忆棒 - 这还不受版本控制。
- 是的,我有“基线”所有代码的备份副本。从 EGit 开始,当您将代码置于源代码控制之下时,我不得不将它从我的 Eclipse 工作区移到 USB 驱动器上的 git 存储库中。因此,如果在学习过程中出现问题,我可以轻松恢复。我还没有对代码进行重大更改,因为我仍在学习。
Note: Using Github is not an option.
注意:使用 Github 不是一种选择。
Purpose/Goal:
目的/目标:
What I am trying to do is keep the code as much in order, with version control, as possible by using Git, but in setting it up at work, for some reason I'm a bit afraid it won't work the same when I get home. (Side note: I sense a "This is of the beauty of git." type answer somewhere.)
我想要做的是通过使用 Git 尽可能保持代码的有序性和版本控制,但是在工作中设置它时,出于某种原因,我有点担心它在以下情况下无法正常工作我回家(了。(旁注:我感觉到“这是 git 的美妙之处。”在某处输入答案。)
My questions are:
我的问题是:
- Using Git as a version control system, what is a best practice for this type of setup?
- Should I leave it on the USB stick just use that repository for everything?
- 使用 Git 作为版本控制系统,这种设置的最佳实践是什么?
- 我应该将它留在 USB 记忆棒上,只使用该存储库来处理所有内容吗?
Sorry for the length, but I wanted to provide as much information as possible. Thanks ahead of time for any information anyone can provide after wading through my novel.
抱歉篇幅过长,但我想提供尽可能多的信息。提前感谢任何人在浏览我的小说后可以提供的任何信息。
回答by Dave G
Try keeping a bare repo on the usb stick and clone it to the machines you are working on.
尝试在 U 盘上保留一个裸仓库并将其克隆到您正在使用的机器上。
Before you pack up for the day or complete to remove your stick, push your changes back to the "origin" (which is the bare repo on the stick).
在您打包一天或完成移除您的棒之前,将您的更改推回到“原点”(这是棒上的裸仓库)。
When you open up on your other workstation (home?) fetch your changes.
当您在其他工作站(家?)上打开时,获取您的更改。
回答by Abizern
Using the USB stick to keep the code and the repository on is one option - you get the advantages of portability andversion control.
使用 U 盘来保存代码和存储库是一种选择 - 您可以获得可移植性和版本控制的优势。
But, another way to do this is to keep a bare repo on the USB stick (or dropbox) and on each machine that you want to use the code, make a clone of this. When you finish doing what you are doing you can just push your changes upstream (to the USB stick or Dropbox or wherever).
但是,另一种方法是在 U 盘(或保管箱)上保留一个裸存储库,并在您要使用代码的每台机器上复制它。当你完成你正在做的事情时,你可以将你的更改推送到上游(到 U 盘或 Dropbox 或任何地方)。
Having a bare clone portable means that if you forget (or $DEITY forbid) lose the stick in it's travels, you won't be left holding your…without any code to work on. You can recreate a clone from any of the repositories if you've lost the key, and, if you forget the key at home or work or somewhere else, there is always something you can do on your project and merge the changes with the key when next they are together.
拥有一个可移植的裸克隆意味着如果你忘记(或 $DEITY 禁止)在它的旅行中丢失了棍子,你将不会拿着你的......没有任何代码可以工作。如果您丢失了密钥,您可以从任何存储库重新创建一个克隆,并且如果您在家中、工作场所或其他地方忘记了密钥,您总可以在您的项目中执行一些操作并将更改与密钥合并下次他们在一起的时候。
回答by Daenyth
One common solution is to keep a bare repo in dropbox and push/pull with that to keep your computers in sync.
一种常见的解决方案是在 Dropbox 中保留一个裸存储库并通过它进行推/拉以保持您的计算机同步。
回答by Gene De Lisa
Just a suggestion:
只是一个建议:
I use Truecrypt with my USB sticks. My code goes into a tc volume. In case I lose the stick - which is fairly common with those things - the finder doesn't get my code.
我在 U 盘上使用 Truecrypt。我的代码进入 tc 卷。万一我丢失了棍子——这些东西很常见——查找器不会得到我的代码。
回答by Philip Oakley
Another way is via bundles
. This assumes you are using an independent machine, see how-to-use-git-in-a-sneakernet-environment
另一种方式是通过bundles
。这假设您使用的是独立机器,请参阅how-to-use-git-in-a-sneakernet-environment