over 2 years ago

Today I was be asked by my colleague "How to maintain (Git) commits which is local only such configurations?".

Commits like these should always be with the development branch, however, we don't want them to be pushed back to repo.

The simplest way is to put those file paths in .gitignore file - a text file indicates Git to ignore files from revision tracking. However, sometimes we can't just ignore them from revisioning, ex: config.php. We need them to be tracked by Git, and also part of the changes stay in local at the same time.

For this circumstance, I'll maintain two branches locally, one is master and another is config. Both of them are setting upstream to origin/master, but the config branch will never push commits back to repo, instead, it pulls only. And the config branch is always leading some commits which you don't want them to be pushed back.

For further explaination, let's create the config branch and set the its upstream to origin/master. ↓↓↓

$ git branch --set-upstream origin/master config
$ git checkout config

And the history tree will looks like this after checked-in several local commits.

m0---m1---m2---m3---m4   <---[master]
                      \
                       \
                        c0---c1---c2   <<===[[config]]

The local commts may contain the necessary configurations which make your development enviroment works, so we coding/developing on the branch config. This is the tree graph it looks like after we've done some works. (remember we still on branch config which contains both local commits and works)

m0---m1---m2---m3---m4   <---[master]
                      \
                       \
                        c0---c1---c2---w0---w1   <<===[[config]]
                                    ^^^^^^^^^^

Now, assume we've done some works (w0, w1), and want then to be pushed back to repo. Here is the instructions: checkout the master branch, pick up the works we've done from config branch (NOTE: be avoid the local commits), then push them back.

$ git checkout master
$ git cherry-pick config~2...config
$ git push origin master
m0---m1---m2---m3---m4---`w0---`w1   <<===[[master]]
                     \^^^^^^^^^^^^
                      \
                       c0---c1---c2---w0---w1   <---[config]

Then check-out config branch and pull again.

$ git checkout config
$ git pull

Finally we got works to be pushed back and local commits still stay in local.

m0---m1---m2---m3---m4---`w0---`w1   <---[master]
                                 \
                                  \
                                   c0---c1---c2   <<===[[config]]
 
over 2 years ago

(更新 2014/07/24 YouTube 已經取消數量 100 的限制)

  寫個跟程式沒有太大關係的小小發現。

  YouTube 有個好用的功能,就是在所有播放器上都有個小小像是「讚」的按鈕,按下去後會保存到「喜歡的影片」中,日後可以瀏覽你所點過讚的影片。這功能或許大家還不陌生,但是有個小小的缺點,「喜歡的影片」數量會有 100 個的限制,較早先所加進來的影片會被新加進來的影片推出清單之外,以確保清單中永遠只保留最新 100 個影片。這難免會有點小小的遺撼,因為我們可能無法記錄 n 年前甚至 n 個月前喜歡過哪些影片。

  現在讓 Louis 來告訴大家,如何來利用 RSS 訂閱來保存歷史記錄。當然,首先你必需要有 RSS 閱讀器。以 Louis 來說,慣用的是 Feedly。至於用哪一款 RSS 閱讀器影響不大,Feedly 的好處是,它可以在雲端自動幫你 RSS 的訂閱來源做同步,確保你訂閱資料比較不會遺失或錯過。(個人推薦!)

  突破 100 個限制所運用的原理是,YouTube 會為每一個播放清單提供一個 RSS 格式的網址,這個網址我們可以用 RSS 閱讀器來訂閱。然而這網址所吐出來的資料仍然有 100 筆的限制,所以我們必需藉助 RSS 閱讀器同步的功能,將最新更新的清單資料保存至本地端,如此便能在本地端有一份歷史記錄。

  以下是詳細的做法。

  先開啟 YouTube 帳號首頁,點擊「播放清單」進入。↓↓↓

  在「播放清單」列表裡點擊「喜歡的影片」進入。↓↓↓

  這時候會看到「喜歡影片」的列表,請把注意力移到網址列。↓↓↓

  我們把網址列“.../playlist?list=”之後那一串字複製下來,以上面範例中來說,那一串字便是「LL6PU8SUI3qKJ29mv10IwCYA」。

  接下來,我們開啟自己所慣用的 RSS 閱讀器。以 Feedly 為例,在訂閱欄裡輸入以下網址:

http://gdata.youtube.com/feeds/api/playlists/LL6PU8SUI3qKJ29mv10IwCYA

  當然,你要把「LL6PU…」置換成你所複製下來的那一串字串,然後 按下「訂閱」。↓↓↓ (完成!)

  訂閱完成後,RSS 閱讀器在每次同步時便會保留下一部份清單複本,如此日積月累,即使 YouTube 刪掉了部分舊的清單內容,你仍然可以在已同步過的訂閱內容中留下過往的記錄。

  同時,你也可以選擇把 RSS 網址分享給有閱讀 RSS 習慣的好友,或者把好友的「喜歡的影片」清單加到自已的 RSS 閱讀器裡,時時掌握好友的喜好動向。