`
jarry-li
  • 浏览: 41587 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Ruby On Rails的第一个应用(四)--使用Git

阅读更多

1.环境及配置

在开发环境安装完成后,就配置了git。其实在刚创建应用程序的时候应该使用git了。

git前期要做的配置,基本上就是之前我们设置的姓名和邮箱地址。另外在根目录下还会有一个.gitconfig文件,大概为:

 

[user]
name = ....
email = ....
 

 

不过我是没有找到 - -!。可以用git repo-config --get-regexp user.*验证配置的信息

Rails提供了一个名为.gitignore的文件,配置git哪些文件不需要加入版本控制,/.gitignore:

 

# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile ~/.gitignore_global
 
# Ignore bundler config
/.bundle
 
# Ignore the default SQLite database.
/db/*.sqlite3
 
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
 
 

 

2.使用

首先需要初始化一个储存库,然后添加所有文件,然后再提交,提交的时候可以也应该把相应文件的说明信息作为参数下起提交;

E:\works\ruby\depot>git status
fatal: Not a git repository (or any of the parent directories): .git
 
E:\works\ruby\depot>git repo-config --get-regexp user.*
WARNING: git repo-config is deprecated in favor of git config.
user.name Jarry Li
user.email jarry-li@163.com
 
E:\works\ruby\depot>git init
Initialized empty Git repository in E:/works/ruby/depot/.git/
 
E:\works\ruby\depot>git add .
 
E:\works\ruby\depot>git commit -m "Depot Scaffold"
[master (root-commit) 79de108] Depot Scaffold
 59 files changed, 1855 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 Gemfile
 create mode 100644 Gemfile.lock
 create mode 100644 README.rdoc
 create mode 100644 Rakefile
 create mode 100644 app/assets/images/cs.jpg
 create mode 100644 app/assets/images/logo.png
 create mode 100644 app/assets/images/rails.png
 create mode 100644 app/assets/images/rtp.jpg
 create mode 100644 app/assets/images/ruby.jpg
 create mode 100644 app/assets/javascripts/application.js
 create mode 100644 app/assets/javascripts/products.js.coffee
 create mode 100644 app/assets/stylesheets/application.css
 create mode 100644 app/assets/stylesheets/depot.css
 create mode 100644 app/assets/stylesheets/products.css.scss
 create mode 100644 app/assets/stylesheets/scaffolds.css.scss
 create mode 100644 app/controllers/application_controller.rb
 create mode 100644 app/controllers/products_controller.rb
 create mode 100644 app/helpers/application_helper.rb
 create mode 100644 app/helpers/products_helper.rb
 create mode 100644 app/mailers/.gitkeep
 create mode 100644 app/models/.gitkeep
 create mode 100644 app/models/product.rb
 create mode 100644 app/views/layouts/application.html.erb
 create mode 100644 app/views/products/_form.html.erb
 create mode 100644 app/views/products/edit.html.erb
 create mode 100644 app/views/products/index.html.erb
 create mode 100644 app/views/products/new.html.erb
 create mode 100644 app/views/products/show.html.erb
 create mode 100644 config.ru
 create mode 100644 config/application.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/backtrace_silencers.rb
 create mode 100644 config/initializers/inflections.rb
 create mode 100644 config/initializers/mime_types.rb
 create mode 100644 config/initializers/secret_token.rb
 create mode 100644 config/initializers/session_store.rb
 create mode 100644 config/initializers/wrap_parameters.rb
 create mode 100644 config/locales/en.yml
 create mode 100644 config/routes.rb
 create mode 100644 db/migrate/20130314064527_create_products.rb
 create mode 100644 db/schema.rb
 create mode 100644 db/seeds.rb
 create mode 100644 doc/README_FOR_APP
 create mode 100644 lib/assets/.gitkeep
 create mode 100644 lib/tasks/.gitkeep
 create mode 100644 log/.gitkeep
 create mode 100644 public/404.html
 create mode 100644 public/422.html
 create mode 100644 public/500.html
 create mode 100644 public/favicon.ico
 create mode 100644 public/index.html
 create mode 100644 public/robots.txt
 create mode 100644 script/rails
 create mode 100644 test/fixtures/.gitkeep
 create mode 100644 test/fixtures/products.yml
 create mode 100644 test/functional/.gitkeep
 create mode 100644 test/functional/products_controller_test.rb
 create mode 100644 test/integration/.gitkeep
 create mode 100644 test/performance/browsing_test.rb
 create mode 100644 test/test_helper.rb
 create mode 100644 test/unit/.gitkeep
 create mode 100644 test/unit/helpers/products_helper_test.rb
 create mode 100644 test/unit/product_test.rb
 create mode 100644 vendor/assets/javascripts/.gitkeep
 create mode 100644 vendor/assets/stylesheets/.gitkeep
 create mode 100644 vendor/plugins/.gitkeep

 

如果要回到原来的状态用命令:git checkout

 

在有更新之后,要提交之前,可以先通过git status来查看修改了哪些文件:

E:\works\ruby\depot>git status
# On branch master
nothing to commit (working directory clean)

 

到现在为止我已经把验证和单元测试都做完了才用git,所以没有修改集体地方;如果在创建完脚手架之后就提交应用程序,到现在执行git status的话我们就应该可以看到:

# On branch master
# Change but not updated:
#   (use "git add <file>..." to update what will be committed)
# 
# modified: app/models/product.rb
# modified: test/fixtures/products.yml
# modified: test/functional/products_controller_test.rb
# modified: test/unit/product_test.rb
...
# no changes added to commit (use "git add" add/or "git commit -a")
 

 

如果只修改了一些现有的文件并没有增加任何新的文件,可以结合git add和git commit命令,然后只要运行带-a参数的git commit命令如你现在有更新的话,可以:

git commit -a -m 'Validation!'

 

------update - 201307-12-------

git将本地仓库上传到远程仓库 

 

 

在已有的git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中,从而开始一个新的项目

 

首先,在本地新建文件夹abc(使用git用户),进入到abc里面,然后git init。这样就在本地初始化了一个git项目abc

然后,登录到远程的git服务器上,到gitrepo目录下面,mkdir abc.git。然后进入abc.git目录。git  --bare init。这样就在服务器端建立了一个空的git项目。

之后,在本地,进入到abc目录里面,增加远程仓库。git remote -v 显示项目目前的远程仓库,因为是新建项目,所以结果为空。git remote add origin git://127.0.0.1/abc.git这样就增加了远程仓库abc

最后,commit提交本地代码,git push origin master这样就把本地的git库上传到了远程git服务器的git库中了

 

 

参见:

http://blog.chinaunix.net/uid-17260303-id-3000999.html 

http://progit.org/book/zh/ch2-5.html

http://progit.org/book/zh/ch4-4.html

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics