个人GIT存储库
我在工作中使用 BitKeeper,我想在家里为自己做一个基本的代码备份(考虑到我很少备份)
//我以前从未使用过 git,所以我需要很多帮助
我认为这可能是个好主意在我的家庭服务器上有一个 git 存储库,然后当我为学校、工作或个人编写代码时,我可以简单地从我的家庭服务器上克隆分支,然后在我完成工作时将它们推回。
// 如果这不是 git 的工作方式,或者我应该如何执行此操作,请纠正我
我已经在我的家庭服务器上安装了 git,现在想知道通过 ssh 设置它的最佳方法,git deamon ??
我的服务器的 ssh 端口已转发,我是否必须为 git 添加新端口?
最后,这个组织使用 git 是否有意义,或者是否有更好的产品适合我,
谢谢
I use BitKeeper at work, and I would like to have a basic code backup for myself at home (considering I back up very rarely)
// I have never used git before so I need lots of help
I thought it might be a good idea to have a git repository on my home server, and then as I write code for school, work or personally I could simply clone branches from my home server work on them then push them back when I am done my work.
// Please correct me if this is not how git works, or how I should be doing this
I have installed git on my home server and would now like to know the best way to set it up, over ssh, git deamon ??
My server's port for ssh is already forwarded must I add new ones for git?
And finally does this organization make sense to use git or is there a better product for me
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Git 非常适合版本控制和“备份”用途。如果您想从多台计算机访问文件,正如您所描述的,让 Git 存储库“启动并运行”的最轻松的方法是使用 Github.com。
Github.com 提供免费空间来托管公共 Git 存储库(它面向开源软件)。通过付费计划(7 美元/月起),Git 将为您提供完全私有存储库的空间,只有您(或您允许的人)才能访问。
否则,您可以自己在自己的服务器上安装 Git,在这种情况下,我建议您设置 SSH 密钥并通过 SSH 访问您的存储库(为了便于配置和安全)。在您的服务器上,您可以进入要存储存储库的文件夹并设置一个“空”存储库,如下所示:
然后在本地,您可以通过向本地代码库添加 git“remote”来添加此新存储库的位置:
现在你有了一个“原始”服务器,你可以随意推送/拉取。
安装 Git
如果您使用的是 Windows,则应该安装 msysgit 并接受默认值(我喜欢启用将 Git 添加到我的右键单击上下文菜单中的选项)。然后,我使用 Git Bash 命令行实用程序来使用 Git,但它也附带了一个基本的 GUI 工具。
如果您使用的是 Mac,则可以下载 Mac安装程序映像并按照其说明进行操作。
如果您使用的是 Linux,则可以使用包管理器来安装 git。例如,在最新版本的 Ubuntu 上,您可以运行:
使用 Git
There's an online Git Book 和 git 手册页,但这里有一些基础知识。
创建一个文件夹“git-enabled”:
将此文件夹中的所有当前文件添加到 git 的版本控制中:
将这些文件提交到本地 Git“暂存区域”:
准备好后,可以将此本地暂存区域推送到远程存储库,例如 github 或您自己的服务器(假设您已经有一个名为“origin”设置的远程存储库,请参见上文):
它将默认的“master”分支推送到您的远程存储库。如果您需要使用远程存储库主分支中的文件更新本地副本,请改为“拉取”:
每当您进行新工作时,您都希望创建一个分支并在那里工作,这样您就不会混淆主分支,因此,一旦您知道更改正在起作用,您就可以合并它们。所以...
要创建一个新分支并开始在其中工作,您可以“签出”该分支并通过以下操作同时创建它:
当您在
new_branch
中完成后,再次签出 master 分支并合并您的更改:如果您想在合并之前查看两个分支的差异,请使用 git diff 命令:
要查看所有提交的日志,请使用 git log >:
按“q”退出日志视图。
在任何一天,这些都是我最常使用的命令。
Git is great for version control and "backup" uses. If you want to access files from more than one computer, as you describe, the most pain-free way of getting a Git repository "up and running" is to use Github.com.
Github.com provides free space to host public Git repositories (it's geared towards open source software). With a paid plan (starting $7/month), Git will give you space for completely private repositories, which only you (or people you allow) can access.
Otherwise, you can install Git yourself on your own server, in which case I'd recommend you setup SSH keys and access your repo over SSH (for ease of configuration and security). On your server, you can go into the folder you want to store your repo in and setup an "empty" repo like this:
Then locally, you can add the location of this new repo by adding a git "remote" to your local codebase:
Now you have an "origin" server, which you can push to/pull from at will.
Installing Git
If you're on Windows, you should install msysgit and accept the defaults (I like to enable the option for Git to be added to my right-click context menu). I then use the Git Bash command-line utility to use Git, but it comes with a basic GUI tool as well.
If you're on a Mac, you can download the Mac installer image and follow its instructions.
If you're on Linux, you can use your package manager to install git. On the most recent version of Ubuntu, for example, you'd run:
Using Git
There's an online Git Book and the git man pages, but here are some basics.
Make a folder "git-enabled":
Add all of your current files in this folder to git's version control:
Commit these files to your local Git "staging area":
When you're ready, you can push this local staging area to a remote repo, like github or your own server (assumes you already have a remote called "origin" setup, see above):
Which pushes the default "master" branch out to your remote repo. If you need to update your local copy with files from your remote repo's master branch, do a "pull" instead:
Whenever you do new work, you want to create a branch and work there, so you don't muddle the master branch, and so you can merge your changes once you know they're working. So...
To create a new branch and start working in it, you can "checkout" the branch and create it simultaneously with the following:
When you're done in
new_branch
, checkout the master branch again and merge your changes:If you want to see a diff of the two branches before merging, use the
git diff
command:To see a log of all your commit, use
git log
:Press 'q' to exit the log view.
In any given day, those are the commands I use most.
您可以将存储库或分支克隆到任何位置以对其进行处理。
我个人研究过 ssh,它不需要设置守护进程。
它将使用相同的 ssh 端口,不需要任何新内容。
这是入门教程和其他一些 有帮助 资源。
You can clone repos or branches to any location to work on them.
I personally go over ssh which does not require a deamon to be setup.
It will use the same ssh port, nothing new required.
Here's a tutorial to get you started and some other helpful resources.