- 浏览: 852884 次
- 性别:
- 来自: lanzhou
文章分类
最新评论
-
liu346435400:
楼主讲了实话啊,中国程序员的现状,也是只见中国程序员拼死拼活的 ...
中国的程序员为什么这么辛苦 -
qw8226718:
国内ASP.NET下功能比较完善,优化比较好的Spacebui ...
国内外开源sns源码大全 -
dotjar:
敢问兰州的大哥,Prism 现在在12.04LTS上可用么?我 ...
最佳 Ubuntu 下 WebQQ 聊天体验 -
coralsea:
兄弟,卫星通信不是这么简单的,单向接收卫星广播信号不需要太大的 ...
Google 上网 -
txin0814:
我成功安装chrome frame后 在IE地址栏前加上cf: ...
IE中使用Google Chrome Frame运行HTML 5
Want to be a dark-knight git-wielding Rails coder? Here’s a quick run-through of how you might want to set up git with a new Rails app.
I’m assuming you’ve managed to compile and install the 5TB of dependencies required to install git (sudo port install git-core
). You’ll also want to set your name and email in the global config (git config --global user.name "Your Name"; git config --global user.email "your@email.com"
).
For the impatient
Create a top, project-level .gitignore
file containing:
log/*.log
tmp/**/*
doc/api
doc/app
Create some .gitignore
files so the empty directories get tracked:
$ touch log/.gitignore
$ touch tmp/.gitignore
and commit:
$ git add .
$ git commit -m "Added initial Rails app"
Read on if you want a step-by-step guide as to what’s going on.
Creating a new edge rails app
Firstly, let’s create a brand-spanking-new Rails 2.0 app called YeOldGitYou from rails trunk.
$ svn up ~/Sites/rails/trunk/
At revision 8276.
$ ruby ~/Sites/rails/trunk/railties/bin/rails YeOldGitYou
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create script/process
create test/fixtures
create test/functional
create test/integration
create test/mocks/development
create test/mocks/test
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application.rb
create app/helpers/application_helper.rb
create test/test_helper.rb
create config/database.yml
create config/routes.rb
create public/.htaccess
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/boot.rb
create config/environment.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/console
create script/destroy
create script/generate
create script/performance/benchmarker
create script/performance/profiler
create script/performance/request
create script/process/reaper
create script/process/spawner
create script/process/inspector
create script/runner
create script/server
create script/plugin
create public/dispatch.rb
create public/dispatch.cgi
create public/dispatch.fcgi
create public/404.html
create public/422.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
Creating a new git repository
Git repository’s are a-dime-a-dozen. There’s no such thing as a working copy, everything’s just a git repository containing copies of other git repositories. When you develop locally you’re committing to a local git repository, stored in the .git
directory of your project.
Let’s init a new git repository in the directory of the rails app:
$ cd YeOldGitYou/
$ git init
Initialized empty Git repository in .git/
A git status
shows a bunch of new untracked files:
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README
# Rakefile
# app/
# config/
# doc/
# log/
# public/
# script/
# test/
nothing added to commit but untracked files present (use "git add" to track)
Ignoring log files
Firstly let’s ignore all log files. Create a .gitignore
file:
$ mate .gitignore
Containing the one line:
log/*.log
Now let’s run git status
again:
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# README
# Rakefile
# app/
# config/
# doc/
# public/
# script/
# test/
nothing added to commit but untracked files present (use "git add" to track)
Notice anything different? Well, there’s our newly created .gitignore file. You’ll also notice the log directory is completely gone. This is bad as the Rails logger will throw a big error when it tries to create your development.log
when you boot up the server. So why has the log directory disappeared?
Git doesn’t track empty directories and because of our ignore statement git can’t see anything of interest in /log
.
Even though it’s a bit of a PITA there are supposedly good reasons for this.
The work-around is to create a .gitignore
file in the empty directory.
$ touch log/.gitignore
Let’s run git status
again to see what’s changed:
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# README
# Rakefile
# app/
# config/
# doc/
# log/
# public/
# script/
# test/
nothing added to commit but untracked files present (use "git add" to track)
Woohoo! There’s our log directory.
If your log
directory still isn’t showing up maybe you’re trying to ignore log/*
. In this case git will also ignore the .gitignore
file and you’ll need to use the more specific ignore pattern of log/[^.]*
as per Clifford Heath’s hot tip.
Ignoring the other un-fu files
So what’s left to do? Ignore any files in any of the tmp
subdirectories (I don’t even want to track the tmp directories themselves)
$ touch tmp/.gitignore
and update our main .gitignore
file. Whilst we’re there we’ll add a few other entries that may be needed at some point:
log/*.log
tmp/**/*
# Other useful tidbits
doc/api
doc/app
Committing everything
Before doing a commit in git you need to add files to the “index”. The index represents “my current changeset” and is what will be committed when you type git commit
. We’ve been looking at the status of the index using git status
. Unlike Subversion modified files won’t be committed unless you git add
them first.
To commit everything we’ll git add
all the project files:
$ git add .
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: .gitignore
# new file: README
# new file: Rakefile
# new file: app/controllers/application.rb
# new file: app/helpers/application_helper.rb
# new file: config/boot.rb
# new file: config/database.yml
# new file: config/environment.rb
# new file: config/environments/development.rb
# new file: config/environments/production.rb
# new file: config/environments/test.rb
# new file: config/initializers/inflections.rb
# new file: config/initializers/mime_types.rb
# new file: config/routes.rb
# new file: doc/README_FOR_APP
# new file: log/.gitignore
# new file: public/.htaccess
# new file: public/404.html
# new file: public/422.html
# new file: public/500.html
# new file: public/dispatch.cgi
# new file: public/dispatch.fcgi
# new file: public/dispatch.rb
# new file: public/favicon.ico
# new file: public/images/rails.png
# new file: public/index.html
# new file: public/javascripts/application.js
# new file: public/javascripts/controls.js
# new file: public/javascripts/dragdrop.js
# new file: public/javascripts/effects.js
# new file: public/javascripts/prototype.js
# new file: public/robots.txt
# new file: script/about
# new file: script/console
# new file: script/destroy
# new file: script/generate
# new file: script/performance/benchmarker
# new file: script/performance/profiler
# new file: script/performance/request
# new file: script/plugin
# new file: script/process/inspector
# new file: script/process/reaper
# new file: script/process/spawner
# new file: script/runner
# new file: script/server
# new file: test/test_helper.rb
# new file: tmp/.gitignore
#
Woohoo! So close. Now let’s commit this baby.
$ git commit -m "Created the YeOldGitYou rails app (from rails trunk rev. 8276)"
Created initial commit 64ff1f6: Created the YeOldGitYou rails app (from rails trunk rev. 8276)
45 files changed, 8360 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
create mode 100644 README
create mode 100644 Rakefile
create mode 100644 app/controllers/application.rb
create mode 100644 app/helpers/application_helper.rb
create mode 100644 config/boot.rb
create mode 100644 config/database.yml
create mode 100644 config/environment.rb
create mode 100644 config/environments/development.rb
create mode 100644 config/environments/production.rb
create mode 100644 config/environments/test.rb
create mode 100644 config/initializers/inflections.rb
create mode 100644 config/initializers/mime_types.rb
create mode 100644 config/routes.rb
create mode 100644 doc/README_FOR_APP
create mode 100644 log/.gitignore
create mode 100644 public/.htaccess
create mode 100644 public/404.html
create mode 100644 public/422.html
create mode 100644 public/500.html
create mode 100755 public/dispatch.cgi
create mode 100755 public/dispatch.fcgi
create mode 100755 public/dispatch.rb
create mode 100644 public/favicon.ico
create mode 100644 public/images/rails.png
create mode 100644 public/index.html
create mode 100644 public/javascripts/application.js
create mode 100644 public/javascripts/controls.js
create mode 100644 public/javascripts/dragdrop.js
create mode 100644 public/javascripts/effects.js
create mode 100644 public/javascripts/prototype.js
create mode 100644 public/robots.txt
create mode 100755 script/about
create mode 100755 script/console
create mode 100755 script/destroy
create mode 100755 script/generate
create mode 100755 script/performance/benchmarker
create mode 100755 script/performance/profiler
create mode 100755 script/performance/request
create mode 100755 script/plugin
create mode 100755 script/process/inspector
create mode 100755 script/process/reaper
create mode 100755 script/process/spawner
create mode 100755 script/runner
create mode 100755 script/server
create mode 100644 test/test_helper.rb
create mode 100644 tmp/.gitignore
Aww yeah. Let’s see the status again.
$ git status
# On branch master
nothing to commit (working directory clean)
Freezing rails into vendor
Last thing to do is freeze rails into vendor. I’ll svn export
from the rails trunk copy I used to create the app in the first place:
$ svn export ~/Sites/rails/trunk vendor/rails
Export complete.
and commit it to the git repository:
$ git add vendor/rails
$ git commit -m "Vendor'd rails trunk rev. 8276"
Celebratory drinks
That’s it. Now you can push your local git repo to some remote location and start collaborating all distributed-like.
The final top-level .gitignore
file ended up being:
log/*.log
tmp/**/*
doc/api
doc/app
发表评论
-
Rails 3 Beta版本月将出 Merb融合带来选择
2010-01-11 09:48 1425Rails 3,目前流行Web开发框架Rails的一个升级版 ... -
MerbAdmin:Merb数据管理好帮手
2010-01-11 09:43 910Merb中要加入类似Django的Admin功能早有传闻,如今 ... -
rails cms
2009-12-28 20:29 1672Rails CMS alternatives ======= ... -
Generating Thousands of PDFs on EC2 with Ruby
2009-12-24 18:01 1045The Problem For about two mont ... -
Shrink your JavaScript with the Google Compiler Rails Plugin
2009-11-16 11:27 937Like it or not, JavaScript has ... -
Thank you, Rails
2009-11-06 18:21 571It’s fashionable, or perhaps in ... -
Top 50 Ruby on Rails Websites
2009-10-31 15:18 949We’re big fans of Ruby on Rails ... -
Let a human test your app, not (just) unit tests
2009-10-31 09:26 863I’m a big believer in unit test ... -
Heroku Gets Add-Ons: Serious Ruby Webapp Hosting Made Easy
2009-10-30 07:37 918Heroku is a Ruby webapp hosti ... -
Rails + Google Analytics = easy goal tracking
2009-10-29 20:38 898Google Analytics is an indis ... -
Integrating Flickr into your rails website
2009-10-29 20:37 1074In this post I’m going to show ... -
Ruby on Rails Roadshow in Austin Thursday
2009-10-29 14:25 812Justin Britten founded Prefine ... -
Ruby on Rails and the importance of being stupid
2009-10-21 08:13 815A tale of two servers… Server ... -
How a 1-Engineer Rails Site Scaled to 10 Million Requests Per Day
2009-10-20 14:49 780Ravelry is an online knitting ... -
Installing Rails on CentOS 5
2009-10-20 14:24 1201Note: Since this post origina ... -
CentOS配置lighttpd和rails
2009-10-20 14:22 1129lighttpd版本:1.4.18 fastcgi版本: ... -
Cells:将组件开发带入Ruby2.3
2009-10-20 09:17 1122cells "将使得面向组 ... -
High Quality Ruby on Rails Example Applications
2009-10-15 16:34 1470Sometimes to best way to get ... -
Install Passenger on Ubuntu
2009-10-07 10:17 814Phusion Passenger is one of the ... -
Installing Ruby on Rails with Apache on Ubuntu 9.04 (Jaunty)
2009-10-07 10:00 1022Installing Passenger and Depe ...
相关推荐
Ruby on Rails helps you ... Additionally, this edition now works on Ruby 2.0, a new release of Ruby with substantial functional and performance improvements., This edition is for Rails4.0 and beyond.
"Learn Version Control with Git" is a beginner-friendly step-by-step course. The book doesn't require a deep technical background. Instead, it's aimed at beginners of version control and/or ...
With this fully revised new edition, take a holistic view of full-stack development to create usable, high-performing applications with Rails 5. Rails is a great tool for building web applications, ...
《Agile Web Development with Rails》是一本经典的Rails开发指南,中文版的出版使得更多的中国开发者能够深入理解并应用敏捷开发方法与Ruby on Rails框架。这本书是Rails开发者的必备参考资料,它详细介绍了如何...
Ruby on Rails offers a robust platform for agile web development, combining powerful features with a philosophy that prioritizes developer productivity and application maintainability. Whether you’re...
Your Ruby on Rails ...This new edition has been updated to Rails 5.2 and RSpec 3.7 and contains full coverage of new Rails features, including system tests and the Webpack-based JavaScript setup.
书中的"Pragmatic.Bookshelf.Agile.Web.Development.with.Rails.2nd.Edition.Dec.2006.eBook-BBL"可能是该书籍的电子版文件,它包含了全书的章节和内容。读者可以通过这个电子版深入学习Rails开发的各种技巧和最佳...
Ruby on Rails helps you produce high-quality, beautiful-looking web ... Additionally, this edition now reflects Ruby 1.9, a new release of Ruby with substantial functional and performance improvements.
This pioneering book is the first resource that deep dives into the new Rails 3 APIs and shows you how use them to write better web applications and make your day-to-day work with Rails more ...
Agile Web Development with Rails, Third Edition by Sam Ruby, Dave Thomas, David Heinemeier Hansson Rails just keeps on changing. Rails 2, released in 2008, brings hundreds of improvements, including...
我做 rails 开发人员已经一年多了,每次我必须部署一个 rails 应用程序时,我总是想拿至少 15 只无辜的小猫,用一把浸在强酸中的长柄斧暴露它们的内脏足以扭曲时空连续体。 让我告诉你两个主要原因:1. 建立基础...
upvote, Rails 社区共享平台 Upvote Upvote 是一个免费的开源社区共享平台,如产品搜索或者 Reddit 。想看看它看起来像什么? 查看在Heroku上运行的演示。配置有关配置 。通过。Facebook或者GitHub进行