简介
第一次写开元项目贡献,并且已经被并入,记录一下过程与总结。写的是GitLab的一个feature, 主要是在现存的repository中上传文件,和替换现存repository中已经存在的文件。原来标题是 ‘add “replace” and “upload” functionality’。
熟悉项目架构
刚开始写的时候首先要熟悉项目的架构, GitLab 是用的 Ruby on Rails, 关于 Ruby on Rails 后期有时间的话会把自己的学习总结一下然后分享出来。这里简要的写两个主要的概念。
MVC 框架
Ruby on Rails 文件目录结构
File/Folder | Purpose |
---|---|
app/ | Contains the controllers, models, views, helpers, mailers and assets for your application. You’ll focus on this folder for the remainder of this guide. |
bin/ | Contains the rails script that starts your app and can contain other scripts you use to setup, deploy or run your application. |
config/ | Configure your application’s routes, database, and more. This is covered in more detail in Configuring Rails Applications. |
config.ru | Rack configuration for Rack based servers used to start the application. |
db/ | Contains your current database schema, as well as the database migrations. |
Gemfile Gemfile.lock | These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the Bundler website. |
lib/ | Extended modules for your application. |
log/ | Application log files. |
public/ | The only folder seen by the world as-is. Contains static files and compiled assets. |
Rakefile | This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application. |
README.rdoc | This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on. |
test/ | Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications. |
tmp/ | Temporary files (like cache, pid, and session files). |
vendor/ | A place for all third-party code. In a typical Rails application this includes vendored gems. |
PR 过程以及开发环境
PR 的过程
开发环境
测试
遇到问题
git 使用
在整个过程中对于git的使用感觉自己学习的比较多,有几次甚至可以说起死回生。
怎样把 remote repository 最近的更新并入自己 forked repository
# Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream
# Make sure that you're on your master branch:
git checkout master
# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:
git rebase upstream/master
# push it to your own forked repository
git push -f origin master
参照 http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository
怎样 squash commit
这里有很好的一片文章介绍如何 squash, 我就不在写了。只是写一下上面没有提到的。
squash conflict 处理
squash 过程中可能会有很多的conflict, 这时候你如果使用
git rebase --continue
然后就会提示那些文件有 conflict, 然后你需要一个个的处理这些冲突,直到最后 squash 成功。
squash 提交
squash 之后就是要把它提交到自己的 master repository 中,这个时候一定要强制 push, 要不然的话就会把 squash 的 commit 加在现有 commit 之后。
git push --force origin master
参照 http://stackoverflow.com/questions/5667884/how-to-squash-commits-in-git-after-they-have-been-pushed
http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
怎样恢复到曾经的commit
自己在 squash commit 的时候不知道要强制 push 到repository, 所以 squashed commit 被加到了原来 repository 中 commit 的最后面,最后想用 hard reset 到最后 commit, 可是最后出了错误。具体的是通过
git reflog
恢复过来的。具体的操作请参照
参照 http://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1