如何在多台计算机上使用 Git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6366054/
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
How do you use Git with multiple computers?
提问by Brian
I'm trying to use git and I have many computers. I usually work on my desktop, but sometimes use laptops.
我正在尝试使用 git 并且我有很多计算机。我通常在台式机上工作,但有时会使用笔记本电脑。
How do you sync source code on git when you go home from work and you didn't finish working on the code? Do you send a patch file through email or just commit to git the incomplete codes?
当你下班回家并且没有完成代码工作时,你如何在 git 上同步源代码?你是通过电子邮件发送补丁文件还是只提交不完整的代码?
I agree the latter is more convenient, but I think it makes the git changelog dirty.
我同意后者更方便,但我认为它会使 git changelog 变脏。
采纳答案by Jonah
Commit your work in progress and push it to a remote branch. When you're ready to merge it into your main branch you can use an interactive rebase to rewrite your history and eliminate "work in progress" commits.
提交正在进行的工作并将其推送到远程分支。当您准备好将它合并到您的主分支时,您可以使用交互式 rebase 来重写您的历史记录并消除“正在进行的工作”提交。
回答by vcsjones
Git has a concept of a "remote", such as a central server to push all of your code. You would push all of your changes to the remote (say from work), then when you get home, you can pull the commits you made from work.
Git 有一个“远程”的概念,比如一个中央服务器来推送你的所有代码。您可以将所有更改推送到远程(例如在工作中),然后当您回到家时,您可以拉取您在工作中所做的提交。
GitHubis an excellent hosted Git solution that saves you the pain of having to set it up yourself. You can learn more about remotes, pushing, and pulling from ProGit.
GitHub是一个出色的托管 Git 解决方案,可以让您免去必须自己设置的痛苦。您可以从ProGit 中了解有关遥控器、推和拉的更多信息。
As far as "incomplete" work, you could use a branch and push your branch to the remote. Branches allow you to create a "branch" of code off of the master (sometimes called a trunk). When you are done, you can merge all of the changes back to master. You can read more about branching here
至于“未完成”的工作,您可以使用一个分支并将您的分支推送到远程。分支允许您从主程序(有时称为主干)创建代码的“分支”。完成后,您可以将所有更改合并回母版。您可以在此处阅读有关分支的更多信息
回答by Abe Voelker
Well first of all you probably want to make sure your employer is okay with this... they might not like it if you're taking company IP home with you. :-)
首先,您可能想确保您的雇主对此感到满意……如果您将公司 IP 带回家,他们可能不喜欢这样做。:-)
The answers about having a dedicated server like GitHub are good, but realize you're limited to either open source (which I doubt your employer would like) or having to pay for a small number of private repositories ($7 for 5 private repos, currently).
关于拥有像 GitHub 这样的专用服务器的答案很好,但要意识到您仅限于开源(我怀疑您的雇主会喜欢)或必须支付少量私有存储库(目前 5 个私有存储库 7 美元) )。
IMO the simplest thing to keep a copy of your git repo on your phone or a USB stick, adding the main repo as a remote. Sync this repo with your main one before you leave to go home. You don't need to set up a server at all; git works happily at the filesystem level.
IMO 最简单的方法是在手机或 USB 记忆棒上保留 git 存储库的副本,将主存储库添加为远程存储。在您离开回家之前,将此存储库与您的主要存储库同步。您根本不需要设置服务器;git 在文件系统级别愉快地工作。
回答by Dhruva Sagar
What you really need is a single server side repository that is available publicly. You can use http://github.com/for the same. Github allows you to create public repositories for free, creating private one's is a paid feature. If you wish to setup your own repository server, you can have a look at https://github.com/sitaramc/gitoliteit's reasonably easy to setup.
您真正需要的是一个可公开使用的单一服务器端存储库。您可以使用http://github.com/进行相同的操作。Github 允许您免费创建公共存储库,创建私有存储库是一项付费功能。如果您想设置自己的存储库服务器,可以查看https://github.com/sitaramc/gitolite,设置起来相当容易。
Once you have a public repository then you can push from your desktop at work and then when home on your laptop, you can then pull to get the latest.
拥有公共存储库后,您可以在工作时从桌面推送,然后在笔记本电脑上在家时,您可以拉取以获取最新信息。