以前的做法 
我的Hexo网站使用Next主题 ,该项目时常有更新。最开始是这样管理源码的,主题源码在themes目录下,作为网站源码的一部分,统一做版本管理,定期手动合入 主题的更新。
使用Git子模块 
添加子模块 
男人要对自己好一点!如果想让生活更加美好,必须要将网站源码和主题源码分开管理。由于主题要根据自己的需求适配,因此要有自己的repo。在Github上将该项目fork,于是我有了一个同名的新仓库。
在网上了解到,一个项目要使用另外一个项目,两者又要单独管理,可以使用submodule或者subtree功能。我觉得subtree操作太复杂了,最终选择了submodule方式。将主题项目作为网站项目的子模块,操作如下:
1 2 3 4 cd  hexo_blog/git submodule add git@github.com:panqiincs/hexo-theme-next.git themes/next/ git add . git commit -m 'add theme next as a submodule'  
对上述操作不清楚的请参考Progit 的说明。
添加上游远程仓库 
主题源码的管理原则是既要保持自己的变更,又要延续上游的变更。因此要将官方的远程仓库添加进来,命名为upstream:
1 2 cd  themes/next/git remote add upsteam https://github.com/theme-next/hexo-theme-next 
查看当前的远程仓库:
1 2 3 4 5 $ git remote -v origin  git@github.com:panqiincs/hexo-theme-next.git (fetch) origin  git@github.com:panqiincs/hexo-theme-next.git (push) upstream        https://github.com/theme-next/hexo-theme-next.git (fetch) upstream        https://github.com/theme-next/hexo-theme-next.git (push) 
日常操作 
提交自己的修改 
根据自己的需求,可以对主题文件进行修改,和普通操作无异:
1 2 3 vim some_files git add modified_files git commit -m 'some comments'  
合入上游的更新 
如果发现远程仓库有更新,首先拉取下来,然后选择是否合入到自己的分支:
1 2 3 4 5 6 7 8 git fetch upstream git checkout master git merge upstream/master vim conflict_files                    git add .                             git commit 'merge upstream updates'  
将新的commits推送到远程origin分支:
提交子模块的更新 
回到网站源码目录,发现有更改未暂存:
1 2 3 4 5 6 7 8 9 $ cd  hexo_blog/ $ git status On branch master Your branch is up-to-date with 'origin/master' . Changes not staged for  commit:   (use "git add <file>..."  to update what will be committed)   (use "git checkout -- <file>..."  to discard changes in  working directory)         modified:   themes/next (new commits) 
提交子模块的更新:
1 2 3 git add . git commit -m 'update theme next'  git push origin master 
在Github上查看网站源码仓库,可以看到themes/next目录后有个@xxxxxx,指向子模块的一个提交,点击可以跳转到panqiincs/hexo-theme-next仓库。