使用git组织大量个人脚本的好方法是什么? [英] What's a good way to organize a large collection of personal scripts using git?

查看:120
本文介绍了使用git组织大量个人脚本的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多我的个人脚本,我想用Git开始版本化。我以前组织过我的代码,如下所示:

pre $ 〜/ code / python / projects /(对于大的东西,每个项目都包含在单个文件夹中)
〜/ code / python / scripts /(单个文件脚本全部包含在此目录中)
〜/ code / python / sandbox /(我的测试区域)
〜/代码/ python / docs /(下载文档)

〜/ code / java / ...(如上)

现在我要开始使用git对我的代码进行版本控制,这样我就可以拥有历史记录并将我的所有代码备份到远程服务器上。



我知道我是否使用SVN我只是将整个〜/ code / 目录保存在一个大型存储库中,但我知道这不是一件好事使用Git来做事情的方式

我在网上看到的大多数信息都建议将所有项目文件夹保存在一个地方(比如,没有用于python或java的单独目录),每个项目都包含它自己的git存储库,并且只需拥有一个包含所有单个的片段目录 - 文件脚本/实验,可以在以后转换为项目。



但我不确定我是如何将所有代码目录合并到一个区域。有没有一种好的方法来保持我的单独的代码目录完好无损,还是不值得付出努力?也许我只是附加到单独的代码目录,因为我从来不知道其他任何东西......



另外(作为一个附注),我想很快就能看到我所有项目和脚本的时间顺序历史。所以我可以看到我最近创建的项目。我曾经通过在我的所有项目的开头保留一个数字来做到这一点, 002project 003project

是否有自动或简单的方式在git中执行此操作,而无需向所有项目名称添加编号?

我对任何实用或者组织你的建议的哲学代码。谢谢!

解决方案


我知道如果我使用SVN, 〜/ code /目录中,但我明白这不是一个用Git做事情的好方法。


理由git阻止人们拥有单一的整体存储库你无法克隆存储库的子目录(就像你可以使用SVN一样)



假设你有 git://blah/somecorp_code.git ,它有数百万次修订,并且是15GB。如果你只是想要这个代码的子目录,很难 - 你要么全部15GB,要么全都没有。



对于个人代码,这真的不是问题 - 我有一个单片git仓库,大约20MB,我可以很高兴地将它克隆到我希望使用它的所有机器上。



没有其他人使用它,没有人承诺,而且我也很少在分支方面做很多事情。它真的只是用它一个很好的同步和远程备份(私人GitHub项目)的花哨撤消系统

我组织它如下:



在存储库的根级别,我有一个代码文件夹(以及一个 sites 文件夹,对于web开发的东西 - 这就是为什么存储库是20MB)



在代码文件夹中,我有各种语言的文件夹( python ruby​​ c 等)

在每个语言目录中,我有两个文件夹, snippets 项目。里面的片段是一堆文件,里面的项目是一系列文件夹。



这些项目是我写的随机事物,但实际上并没有太多工作玩具项目,我不知道我是否可以...... - 项目等)

如果它是一个Python文件,它将在 code / python / snippets / ,如果它不止一个文件进入代码/ python / projects / {项目名称}



当我想公开发布一个项目时(通常在Github上),我创建一个新的仓库,将代码复制到Github并与之同步。



单独的活动项目存储库现在与单片回购无关。我研究了子模块项目,但它不适用于这种用法 - 它旨在简化克隆依赖项,而不是管理一系列不相关的存储库。

我有一个使用Github API自动克隆我所有项目的脚本,或者使用 git pull 更新它们 - 它只是 githubsync.py (我将github.py合并到同一个文件中)。它可以在这里作为gist / 373731



我最初使用githubsync.py将我的项目克隆到我的笔记本电脑和桌面,并在Dropbox中作为备份常规运行它。


I have a large collection of my personal scripts that I would like to start versioning using Git. I've previously organized my code as follows:

~/code/python/projects/ (for large stuff, each project contained in an individual folder)
~/code/python/scripts/ (single file scripts all contained in this directory)
~/code/python/sandbox/ (my testing area)
~/code/python/docs/ (downloaded documentation)

~/code/java/... (as above)

Now i'm going to start versioning my code using git, so that I can have history and backup all my code to a remote server.

I know if I were using SVN I would just keep my entire "~/code/" directory in a large repository, but I understand this is not a good way to do things with Git.
Most info I've seen online suggests keeping all my project folders in a single place (as in, no separate directories for python or java) with each project containing it's own git repository, and simply having a "snippets" directory containing all single-file scripts/experiments that can be converted into projects at a later date.

But I'm not sure how I feel about consolidating all of my code directories into one area. Is there a good way to keep my separate code directories intact, or is it not worth the effort? Maybe I'm just attached to the separate code directories because I've never known anything else...

Also (as a side note), I'd like to quickly be able to see a chronological history of all my projects and scripts. So I can see which projects I created most recently. I used to do this by keeping a number at the beginning of all my projects, 002project, 003project.
Is there automatic or easy way to do this in git without having to add a number to all of the project names?

I'm open to any practical or philosophical code organizing advice you have. Thanks!!!

解决方案

I know if I were using SVN I would just keep my entire "~/code/" directory in a large repository, but I understand this is not a good way to do things with Git.

The reason git dissuade people from having single, monolithic repositories is you cannot clone sub directories of a repository (like you can with SVN)

Say you have git://blah/somecorp_code.git which has millions of revisions, and is 15GB. If you just want a subdirectory of that code, tough - you either get all 15GB or nothing.

For personal code, this really isn't an issue - I have one "monolithic" git repository, which is about 20MB, and I can happily have it cloned on all the machines I wish to use it on.

No one else uses it, no one else commits, and I rarely do much in the way of branching. It's really just use it a fancy-undo-system with nice syncing and remote backup (private GitHub project)

I organised it as follows:

In the root level of the repository, I have a code folder (along with a sites folder, for web-dev stuff - this is why the repository is 20MB)

In the code folder, I have folders for various languages (python, ruby, c etc)

In each language directory, I have two folders, snippets and projects. Inside snippets is a bunch of files, inside projects is a series of folders.

These projects are random things I've written, but don't really work on much (toy projects, "I wonder if I could..."-projects etc)

If it's a single Python file, it goes in code/python/snippets/, if it's more than one file it goes in code/python/projects/{project name}

When I want to publicly release a project (on Github, usually), I create a new repository, copy the code to this and sync it with Github.

The separate "active project" repository is now unrelated to the monolithic repo. I looked into the submodule project, but it is not intended for this usage - it's designed to make cloning dependencies easy, not manage a series of unrelated repositories

I do have a script that uses the Github API to automatically clone all my projects locally, or update them with git pull - it's just self-contained version of githubsync.py (I merged github.py into the same file). It can be found here as gist/373731

I used githubsync.py to clone my projects to my laptop and desktop initially, and also routinely run it inside Dropbox, as a backup.

这篇关于使用git组织大量个人脚本的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆