What have we done in cdnjs in last year (2015)?

Merry Christmas and Happy New Year!

Thanks all the users, developers and the contributors! We did a lot of things in 2015, though there are still many issues that waiting to be solved, we’ll keep working on it, at the end of year 2015 and the beginning of year 2016, let’s have a fast review of the changes and rising in cdnjs during 2015!


  • We now got more than 3.3k stars and about 2.5k forks on GitHub
  • We had 9339 commits in the beginning of 2014, became more than 10k commits since Feburary, and now about 18200 commits
    • 8892 commits were committed in last year!
  • We have more than 1000 contributors in 2015! (Sorry that I don’t remember the contributors count at the beginning of last year)
  • We had only 1220 libraries hosted on cdnjs, but 1669 libraries been hosted now!
    • 449 new libraries added in 2015!

(PS: Above data only calculated the cdnjs main repository, we have some other repos here)


How to setup and deploy ssh keys under linux?

Not a hard working, and there are already many articles talk about that, but many students still don’t know how to do that …

The simple syntax for generating ssh key pair:
$ ssh-keygen -t algorithm -b bits -C "comments"

For example:
$ ssh-keygen -t rsa -b 4096 -C "my first ssh key pair!"

The simple syntax for deploying ssh key:
$ ssh-copy-id username@

For example:
$ ssh-copy-id petex@

If you also have problems with ssh keys, I will suggest you to read the articles below, they are confirmed by myself, I think those are correct and easy versions, and there is no need to write them in my blog again …

3 good articles should be enough …

How to sync/update forked git repository with upstream?

中文版: https://www.peterdavehello.org/2014/02/update_forked_repository/

I found the origin post in Chinese is more popular among all the posts, so just rewrite it in English now :)

Once you forked a repository on GitHub, the commit history from the upstream will stay at the moment you forked it, sometimes we’ll need to update it, so that the parent of our commit won’t be so old, which can help us have a better look, easier to trace git commit history, and prevent some potential or known conflicts, maybe you have other reasons, anyway. This method can also sync a repository between different git servers.

If you forked repository is behind the upstream repository for more than 1k commits and the repository is fat, you can consider to delete your forked repository and re-fork the origin one, it may be faster and more efficient.

Let’s start it.

First, if you didn’t have the repository locally, you have to clone the forked repository to local, you can set the clone depth to save the bandwidth and disk space usage:
$ git clone --depth 1 https://github.com/user/repo.git

(Replace the url to your forked repository)

Once you cloned it, check its ‘remote’, usually you’ll get only one remote after clone, like this:
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)

Now we should add another ‘remote’ – the origin upstream, so that we can pull the updates from, in this case, use read-only git protocol will be faster, more efficient (but note that some firewall may not allow that protocol, so you’ll need to use https in that case):
$ git remote add upstream git://github.com/otheruser/upstreamRepo.git

PS: ‘upstream’ is the name I gave it, you can give it another name as you want.

To verify new added remote, let’s check it again, you should have two remotes now:

origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
upstream git://github.com/otheruser/upstreamRepo.git (fetch)
upstream git://github.com/otheruser/upstreamRepo.git (push)

Now we can start the “update” works, I assume the branch you’re going to update is the master branch, if you are going to update a non-master branch, just checkout to the branch you want, but don’t forget to change the branch from the below examples!

If your branch is only behind the upstream, no any “ahead” commits(which means you didn’t commit any new things on the same branch came from upstream), you can directly pull the updates from upstream:
$ git pull upstream master

If your branch also contains your own commits, you should better pull with “–rebase” parameter:
$ git pull --rebase upstream master

Now, almost done, if there is no error or conflicts(we don’t discuss conflicts here), push your master to origin remote, then you’ll found that your forked repo is fresh again:
$ git push origin master

善用 Git 的 sparse checkout 跟 shallow clone/pull 來提高工作效率

當初也是因為在摸cdnjs才開始接觸到的東西,不過貌似大家平常用不太到,所以很多人不知道有這樣的功能,也是做個筆記,有人問的時候可以直接丟這篇 …

先講shallow clone/pull:

man git-clone理面的說明:

Create a shallow clone with a history truncated to the specified number of revisions.

簡單來說就是把太久以前不需要的歷史給丟掉,大於給定數量以前的commit紀錄就會被忽略,進而省下clone時頻寬、空間及時間,這點在數千到數萬個commits以上的repository理面效果會非常明顯,像travis-ci在做CI build的時候預設的clone depth就是50,很久以前是100,缺點除了git log只看的到一定數量的提交紀錄外,git blame跟bi-sect等會需要trace先前紀錄的功能都會變的不可靠或不可用就是了。

另外一個就是sparse-checkout了,這個功能的作用是只checkout出我們想要的檔案,以cdnjs為例,.git資料夾也才600多MB而以,可是整個專案的資料夾卻高達13GB左右,由於理面的檔案大多是非常容易壓縮的source code(文字檔),所以就會有.git資料夾明明占用很少空間,可是實際上整個專案占用的空間卻非常龐大的現象,而這麼大的專案,很可能會有檔案系統操作的效率低落的問題(尤其在rebase等操作),在我們已知只需要取得某專案某些目錄或檔案的情況下,根本沒必要把所有檔案都checkout出來,這時候就可以使用sparse-checkout,在送pull request到不是自己常態性參與的專案時很好用!


  1. 建立一個空的git專案:
    $ git init new.cdnjs && cd new.cdnjs

  2. 在專案裡面啟用sparse-checkout
    $ git config core.sparseCheckout true

  3. 設定你要checkout哪些檔案(直接寫到.git/info/sparse-checkout,多個規則可寫多行),例如我只要ajax/libs/jquery/底下的所有檔案
    $ echo '/ajax/libs/jquery/*' >> .git/info/sparse-checkout

  4. 設定remote(要從哪裡clone/pull?)
    $ git remote add origin git://github.com/cdnjs/cdnjs.git

  5. 然後就可以開始pull了(這邊可以加上前面說的shallow pull,加上–depth=n)
    $ git pull origin master

到這邊就結束了,整個專案所占用的空間應該會小非常多,這邊以jquery搭配shallow clone depth=10為例,看一下空間使用:
$ du -d 1 -h

18M ./ajax
587M ./.git
605M .


$ du -d 1 -h

682M ./.git
43M ./scratch
16M ./node_modules
12G ./ajax
24K ./test
32K ./build
13G .

高達13GB …

摁 … 少了12GB的checkout快很多啊 …


就直接更改專案底下的.git/info/sparse-checkout檔案,改好之後做一次git reset –hard即可




Microsoft Visual Studio Code Preview and .NET core on Linux


.NET Core如微軟先前所說支援Linux了,甚至連FreeBSD的版本都有(開發中),而目前丟在GitHub上的版本可用的.NET Core API已經有全部的45%了,相信很快就能到八成以上,詳情可參考.NET blog:
.NET Announcements at Build 2015

另外一件大事是Microsoft Visual Studio CodeVisual Studio的 … 兄弟?或說是一個比較初期的opensource版本,據說是based on GitHubatom editor


MicrosoftVisualStudioCodePreviewWebsite我自己裝起來玩的畫面,期待可以變得跟我們認識的Visual Studio愈來愈像XD?