Bowen's Blog

Respect My Authorita.

Set Up Github Page

| Comments

创建一个github账户

设置好用户名,email和github的token

创建一个新的repository,命名规则为username.github.com, 比如我创建的就是iambowen.github.com

设置好remote的repos后在本地创建同样的repos,然后添加README和index.html文件,本地提交

@git push -u origin master@,大约10分钟之后访问username.github.com,就可以看到新添加的index页面,比如我的

安装jekyll模版, @gem install jekyll@

jekyll 是一个文本转换引擎(text transformation engine), 它可以将Texttile/Markdown的标记语言转换为html的layout.通常的site基本结构如下:

1
2
3
4
5
6
7
8
9
|-- _config.yml
|-- _includes
|-- _layouts
|   |-- default.html
|   `-- post.html
|-- _posts
|   |-- 2007-10-29-why-every-programmer-should-play-nethack.textile
|   `-- 2009-04-26-barcamp-boston-4-roundup.textile
|-- _site `-- index.html

_config.yml

保存配置的文件.

_includes 这里保存公用的patilal文件,在 layouts 和 posts 的文件中可以复用这些文件。

_layout 这里保存文章的模版文件

_posts 这里保存blog的文章,文件的格式通常使用YEAR-MONTH-DATE-title.MARKUP,然后github会自动的将这些文件转换. _site 这里的文件可以由命令 @jekyll –pygments@生成之后在命令行启动 jekyll的服务器,@jekyll –server@.通过访问http://127.0.0.1/4000%E5%8E%BB%E9%A2%84%E8%A7%88post._site%E6%96%87%E4%BB%B6%E4%B8%8D%E9%9C%80%E8%A6%81push%E5%88%B0remote repos上,把它加到.gitignore文件中就可以了.

写完一篇blog,预览后,就可以本地提交,push到远程主机上了。过几分钟,应该就能看到博文^_^了.

Don't Panic When You Use Git Reset --hard

| Comments

It’s not a problem when you use to git reset --hard to throw away commit. But often times, you need to first check whether there’s still useful stuff to keeOf course, –soft is the best choice, however, what if you use git reset --hard without realizing that the commit you just throw is useful. And the following should be one solution to this accident.

Given i reset the commit:

1
2
3
$ @git reset --hard HEAD^@

HEAD is now at 43856d7 modify test to raise conflict

Then i use ref the log:

1
2
3
4
$ @git reflog -4@

43856d7 HEAD@{0}: HEAD^: updating HEAD
3378cf7 HEAD@{1}: commit: that part is easy.

And i see 3378cf7 is the commit i just reset, i use git show to see commit detail

1
2
3
4
5
6
$ @git show 3378cf7@

commit 3378cf7f1c8a197492796b3cdb2c79f0183c9efe
Author: bowen <iambowen.m@gmail.com>
Date:   Mon Oct 31 16:26:45 2011 +0800
    that part is easy.

And i check out the commit:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ @git checkout 3378cf7f1c8a197492796b3cdb2c79f0183c9efe@

Note: checking out '3378cf7f1c8a197492796b3cdb2c79f0183c9efe'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 3378cf7... that part is easy.

Then I follow the notification to create a new branch and check log:

1
2
3
4
5
6
7
8
$ git checkout -b recover
$ git log

commit 3378cf7f1c8a197492796b3cdb2c79f0183c9efe
Author: bowen <iambowen.m@gmail.com>
Date:   Mon Oct 31 16:26:45 2011 +0800

    that part is easy.

And i find the commit is in this branch, then i go back to master branch merge recover branch:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$git co master
$git merge recover

Updating 43856d7..3378cf7
Fast-forward
 README   |    1 -
 whatever |    1 +
 2 files changed, 1 insertions(+), 1 deletions(-)
 create mode 100644 whatever

$ git log -1

bc. commit 3378cf7f1c8a197492796b3cdb2c79f0183c9efe
Author: bowen <iambowen.m@gmail.com>
Date:   Mon Oct 31 16:26:45 2011 +0800
    that part is easy.

And we can see the reseted commit is coming back, that part is easy.