实践:合并已存在的git仓库

周五整理机器人线上监控脚本,忽然想起这个脚本还是放在github上管理呀,免费用户在github上的代码都是公开的,谁都可以看。我和一些同事的工作邮箱还在脚本里配置着呢,要是被爬虫抓到就烦人了。

最近才找到一个私有的git仓库,于是想把github上的原有数据移过去,但又要保存以前的commit记录,所以不是简单的mv那么简单了,要折腾一下了。 ;)

结果嘛,当然是终于成功了,所以发此博文分享并记录。

为了让大家看的明白,我重新描述下case如下:
  1. 有2个git仓库:repo1、repo2;
  2. 想将repo1中的文件移入repo2;
  3. repo1的历史日志要保留;
首先,快速创建2个仓库。
1
2
3
4
5
6
7
8
9
10
11
12
13
mkdir repo1
cd repo1
git init
echo "repo1.txt" > repo1.txt
git add repo1.txt
git ci -m "init repo1"
 
mkdir repo2
cd repo2
git init
echo "repo2.txt" > repo2.txt
git add repo2.txt
git ci -m "init repo2"

结果目录路径是:

1
2
3
4
5
6
7
repo1/
repo1/repo1.txt
repo1/.git
 
repo2/
repo2/repo2.txt
repo2/.git

再次注意,想要的效果是:

1
2
3
4
repo2/
repo2/repo1.txt
repo2/repo2.txt
repo2/.git
然后,需要五步命令:
1
2
# 1、将repo1作为远程仓库,添加到repo2中,设置别名为other
[jot@myhost repo2]$ git remote add other ../repo1/
1
2
3
4
5
6
7
8
# 2、从repo1仓库中抓取数据到本仓库
[jot@myhost repo2]$ git fetch other
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ../repo1
 * [new branch]      master     -> other/master
1
2
3
4
# 3、将repo1仓库抓去的master分支作为新分支checkout到本地,新分支名设定为repo1
[jot@myhost repo2]$ git checkout -b repo1 other/master
Branch repo1 set up to track remote branch master from other.
Switched to a new branch 'repo1'
1
2
3
# 4、切换回repo2的master分支
[jot@myhost repo2]$ git checkout master
Switched to branch 'master'
1
2
3
4
5
6
# 5、将repo1合并入master分支
[jot@myhost repo2]$ git merge repo1
Merge made by recursive.
 repo1.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 repo1.txt
可以看到效果了,日志确实还在:
已经完成,可以push到服务器了。
总结:
  1. 大致思路是伪造远程的repo1仓库为repo2的一个分支,然后合并进来;
  2. 若是文件有冲突、或要建立子目录,建议在repo1中先解决,再进行如上操作。
参考资料:
  1. http://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another
  2. http://progit.org/book/zh/ch2-5.html (推荐阅读)

Wp-syntax关键字着色方案的修改方法

觉得默认的着色设置不是很清楚,甚至很难看,就网上找了找方法,想和谐他的着色配置,终于找到了。

方法如下:

修改wp-syntax/wp-syntax.php文件,在122行插入下面内容。

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    $geshi = new GeSHi($code, $language);
    $geshi->enable_keyword_links(false);
    do_action_ref_array('wp_syntax_init_geshi', array(&$geshi));
 //***********************
    $geshi->set_overall_style('color: #000000; font-family:"Consolas",monospace,"Courier New"');  //默认颜色
    $geshi->set_brackets_style('color:#CCB;background-color:#F0F0F0', true); //括号颜色
    $geshi->set_keyword_group_style(1, 'color: #9400D3;font-weight: bold;'); //第一组关键字 new public class
    $geshi->set_keyword_group_style(2, 'color: #DC143C;'); //第二组关键字  true
    $geshi->set_keyword_group_style(3, 'color: #436EEE;'); //第三组关键字 Object ThreadLocal
    $geshi->set_methods_style(1, 'color: #B8860B;'); //第一组方法名称
    $geshi->set_comments_style(1, 'color: #777777;'); //第一组注释
    $geshi->set_comments_style(2, 'color: #33CC66;'); //第二组注释
    $geshi->set_comments_style('MULTI', 'color: #008B45;'); //多行注释
    $geshi->set_strings_style('color: #00CD00;'); //字符串直接量
    $geshi->set_strings_style('color: #00CD00;', false, 'HARD'); //字符串直接量(*)
    $geshi->set_regexps_style(0, 'color: #000088;'); //正则表达式
    $geshi->set_numbers_style('color: #A52A2A;'); //数字
    $geshi->set_symbols_style('color: #4A708B;'); //符号
    $geshi->set_escape_characters_style('color: #99FF00;'); //转义字符
 //***********************
    //START LINE HIGHLIGHT SUPPORT
    $highlight = array();
    if ( !empty($match[4]) )

参考:http://lync.in/customizing-wp-syntax-code-styles/

从plsql导出ddl到PowerDesigner

新接触一个应用系统,表结构是它的灵魂,所以我要先研究表结构。
但是通过plsql看我们的一张张表,实在是看的很累,所以我要导入PowerDesigner。

首先想到的是PowerDesigner直接连接oracle同步,但是遇到了权限问题,折腾了很久,难以搞定。
转念一想,其实需要的就是ddl呀,plsql导出ddl,然后导入到PowerDesigner不就行了!

于是,就这样搞定了,下面是方法:

1、plsql导出ddl:

工具——导出用户对象——选择需要到处的表——多选框:全部不掉——单选框:选单个文件——导出

2、PowerDesigner导入ddl:

快捷键Ctrl+R(DataBase->Update Model From Database)——选择刚才导入的文件——确定

另外:导入时,还支持编码选择、自动重建引用等,不过这次我就没用了,目标已经实现。以后可以试试。:)

firefox8与zBench主题的不兼容解决

firefox 升级至 8.0a2 (2011-08-22),发现和zBench 1.2.7有冲突。
页面样式乱了,右边的侧边栏跑到下边了!

难以忍受!很快研究出了解决方案:

1
2
3
4
5
6
7
8
9
<!-- header.php -->
<body>
  <div id="nav">
  <div style="clear:both"></div> <!-- 增加此行 -->
  <div id="wrapper">
  <div id="header">
  <div id="content">
  <div id="sidebar-border">
……

样式文件也需要小修改一下:

1
2
<!-- style.css -->
#wrapper{overflow:hidden;margin:0 auto;width:960px;} # 960px 改为 961px

然后一切正常了!:)

 

WP高亮插件WP-Syntax与zBench样式的冲突解决小记

以前挑选js高亮插件写了篇博文:WP高亮插件选择:Syntax Highlighter还是WP-Syntax

之前的选择是:Syntax Highlighter
原因是它功能强大,[lang-name]的方式和我的zBench主题样式冲突(<pre><table>标签的样式都有冲突)
图就不给了,已经改掉了。

还有个问题就是Syntax Highlighter在编辑器的富文本模式和源码模式切换时,会造成代码缩进丢失,这个影响可读性,很严重!
当我今天之前一直忍了,因为我一直用源码模式编辑,也没啥问题,嘿嘿~
但是,现在要给团队装高亮插件了,重新权衡,还是选用了WP-Syntax,它首先在切换编辑器时不会丢失缩进,且<pre>的方式或许更加通用。至于CSS的冲突,2分钟就调好了。嘿嘿,速记如下:

zBench样式文件style.css中,直接把pre的定义注释掉吧,交给WP-Syntax控制:

1
2
3
4
5
6
7
8
9
10
11
12
.entry pre{
    overflow:auto;width:95%;
    line-height:16px;
    margin:0 0 20px;
    padding:0 5px 16px;
    color:#555;
    font-family:"Courier New",FixedSys;
    font-size:12px;
    background:#fafafa;
    border:1px solid #ccc;
    border-left:15px solid #ccc;
}

WP-Syntax样式文件wp-syntax.css中,增加2句关于table、td的定义,覆盖zBench的定义:

1
2
3
4
5
6
7
8
9
.wp_syntax table {border: none;  margin:0; }
.wp_syntax td { border: none;}
.wp_syntax {
    background-color: #F9F9F9; /* 改为 #fff 白色*/
    border: 1px solid silver;
    color: #110000;
    margin: 0 0 1.5em;
    overflow: auto;
}

就搞定了!上面可以看到效果!

另外,结合WP-Syntax Editor Integration Plugin,会在wp原生编辑器上增加一个添加代码的按钮,那就更方便了!

再另外,<pre>的通用很重要,这样很多插件,甚至没插件都能支持,[lang-name]就鸡肋了,只有它一个插件支持,用来就不能换,否则,以前的文章要一篇篇改,我还好,就几篇,十几分钟就改完了。但是,我肯定不愿再意重新改一次了!  :(

再再另外,WP-Syntax有个不足,不支持某行高亮,不过这个用的不多,增加支持也不难,先不管了!还有,据不完全统计,WP-Syntax支持136种脚本!

svn设置提交时排除

项目代码中有些文件,确实是需要纳入svn管理,但是却本地人手一份不一样的,又不能提交,如:jtester.properties(里面要配置源码绝对路径)

Windows TortoiseSVN 可以可视化设置,这个大家应该都会。

但是逐渐迁入linux了,这个命令需要研究下了,这是研究结果:

# 查看
svn st --changelist ignore-on-commit
# 增加
svn cl ignore-on-commit coreservice.commontest/src/main/resources/jtester.properties
# 删除
svn cl --remove coreservice.commontest/src/main/resources/jtester.properties

再svn st察看状态:

[jot@jot-200-170 core]$ svn st
? setup/env-install/META-INF/autoconf/conf/auto-config.xml.log
M coreservice.war/src/main/resources/META-INF/autoconf/conf/log4j.xml.vm
M coreservice.war/src/main/resources/META-INF/autoconf/conf/auto-config.xml
 
--- Changelist 'ignore-on-commit':
M coreservice.commontest/src/main/resources/jtester.properties

第一个idea android工程初探

Intellij Idea的第一个android工程创建好了,helloworld也出来了!不着急写点啥,咱也没看过专门的书,就先琢磨下andriod工程的构成。Update:本文档所说的内容,找到了总的官方文档

初始的工程文件不多,如图:

其中几个文件说明下(idea工程相关的就不说了):

  • ./AndroidManifest.xml
    Android的清单文件,详见官方文档。每个应用必须有,为android系统提供有关应用的必要信息,如:java包名、组件描述、权限、测试信息、SDK Api最低要求、必须的库文件等。
  • ./build.xml
  • ./local.properties
  • ./build.properties
  • ./default.properties
    Idea用来build android module的4个ant配置文件,可以先不管。
  • ./proguard.cfg
    应用的保卫者,详见官方文档。用来压缩、优化、混淆、清理代码的,这个工具好,防止逆向反编译,不知道Google有没有留后门哇,嘿嘿怀疑下,等以后熟悉点类再判断。
  • ./res/drawable-hdpi/icon.png
  • ./res/drawable-ldpi/icon.png
  • ./res/drawable-mdpi/icon.png
    图标资源文件,详见:官方文档。高分辨率、中分辨率、低分辨率三种状态的图标显示。
  • ./res/layout/main.xml
    UI组件的布局定义,详见:官方文档
  • ./res/values/strings.xml
    String资源定义,详见:官方文档。为了复用、国际化等等。
  • ./gen/com/jotcmd/R.java
    资源访问静态类,详见:官方文档。gen目录表示自动生成。里面的int值是可以用来定位到目标资源的资源ID。
  • ./src/com/jotcmd/MyFirstActivity.java
    终于是主程序了,这个就是java,就不说了。里面可以把R.java指定的、res里的资源、布局全部绕开不用,但是,何必呢?你不觉得R.java是个好主意吗?反正我是觉得不错。

最后生成的apk文件内部列表是:

[jot@myhost jot_roid]$ unzip -l jot_roid.apk
Archive:  jot_roid.apk
Length      Date    Time    Name
---------  ---------- -----   ----
692  2011-08-10 21:50   res/layout/main.xml
1300  2011-08-10 21:50   AndroidManifest.xml
1220  2011-08-10 21:44   resources.arsc
3966  2011-08-10 21:44   res/drawable-hdpi/icon.png
1537  2011-08-10 21:44   res/drawable-ldpi/icon.png
2200  2011-08-10 21:44   res/drawable-mdpi/icon.png
2088  2011-08-10 21:50   classes.dex
564  2011-08-10 21:50   META-INF/MANIFEST.MF
617  2011-08-10 21:50   META-INF/CERT.SF
776  2011-08-10 21:50   META-INF/CERT.RSA
---------                     -------
14960                     10 files

明显多出的2个文件:

  • classes.dex:如果android的语言是java,那么dex就是jar包了,纠结的Google啊。
  • resources.arsc:strings.xml哪里去了?就在这个文件里,它是可被编译的资源文件包。不可编译的依然在外面。参见:官方文档。TODO:main.xml为什么在外面,有待研究。

暂时只了解类这么些,但是从R.java、resources.arsc、proguard.cfg这些文件,就可以知道,android花了心思让开发者爽。那好吧!爷决定继续宠信你!

 

一个svn分支合并脚本里用到的bash shell语法小总结

周四要合并3个分支,第一次合。尝试写了个脚本。写法发现自己的bash shell真的超不熟练,很多东西要再查google,悲痛,所以总结此文以铭记。

脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
 
cd `dirname $0`
base_dir=$(pwd)
 
if [ $# -lt 2 ] ; then
  echo "USAGE: $0 oldBranch newBranch"
  echo " e.g.: $0 http://XXX/api_1 http://XXX/api_2 merge.log"
  exit 1
fi
 
function ask_Y_N {
  echo -e "\e[31;40;1mCheck Again! Go Next? (Y/N) (default: N)\e[m"
  read dorm
  dorm=${dorm:=N}
  if [ $dorm != Y ] &amp;&amp; [ $dorm != y ]; then
    echo "==&gt;Exit."
    exit 0
  fi
}
 
oldBranch=$1
newBranch=$2
echo -e "oldBranch is: \e[36;40;4m$oldBranch\e[m"
echo -e "newBranch is: \e[36;40;4m$newBranch\e[m"
echo "Meger oldBranch to the newBranch."
ask_Y_N
 
date_str=$(date +%Y-%m-%d_%H:%M:%S)
#echo $date_str $base_dir $1 $2 $3
 
echo -e "\e[32;40;1m1. svn co newBranch.\e[m"
newBranchDir=$base_dir/$(date +%s)_new
svn co $newBranch $newBranchDir
 
echo -e "\e[32;40;1m2. find the oldBranch begin version.\e[m"
bengin_ver=$(svn log --stop-on-copy $oldBranch |grep 'r[0-9]* |' | tail -n 1 | awk -F"[ r|]" '{print $2}')
echo "Begin version: $bengin_ver"
svn log -r $bengin_ver $oldBranch
 
echo -e "\e[32;40;1m3. svn merge --dry-run -r $bengin_ver:HEAD\e[m"
svn merge --dry-run -r $bengin_ver:HEAD $oldBranch $newBranchDir
 
echo -e "\e[32;40;1m4. svn merge --ignore-ancestry -r $bengin_ver:HEAD\e[m"
ask_Y_N
cd $newBranchDir
svn merge --ignore-ancestry -r $bengin_ver:HEAD $oldBranch .
 
echo -e "\e[32;40;1m==&gt; Done. Please do 'svn commit' yourself later!\e[m"
echo "cd $newBranchDir"
echo "svn ci -m 'merge from $oldBranch Details:\\"

从前到后,涉及到的几种bash语法:

  1. 当前shell文件名:$0。line:3
  2. 找shell当前目录:dirname,shell内执行shell,变量赋值。line:3-4
  3. 判断外部传入参数,错误则打印Usage,并退出。line:6-10
  4. 函数运用。直接用函数名,即调用函数。函数定义必须在函数调用之前。line:12-20,27
  5. shell着色。echo -e “\e[31;40; …… \e[m”,详细参见:http://corz.org/public/linux/usr/local/bin/color.sh

/etc/rsyncd.conf 配置

以前的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
id=jot
gid=jot
[1_portal]
path=/home/jot/200g/source/1_portal
read only = no
exclude = /*/target /target /output /web-deploy /setup
allow jot-aliwork
 
[2_core]
path=/home/jot/200g/source/2_coreservice
read only = no
exclude = output web-deploy
allow jot-aliwork

现在的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
uid = nobody
gid = nobody
use chroot = no
read only = true
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
#secrets file = /etc/rsyncd.pwd
 
[1_portal]
        path = /home/jot/workspace/1_portal/
[2_core]
        path = /home/jot/workspace/2_coreservice/
[3_bops]
        path = /home/jot/workspace/3_backoffice/
[4_api]
        path = /home/jot/workspace/4_api/
 
#[cvs]
#        path = /data/cvs
#        comment = CVS repository (requires authentication)
#        auth users = tridge, susan
#        secrets file = /etc/rsyncd.secrets

启动方式:

1
2
3
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
sudo /etc/rc.d/rsyncd restart
rsync -avz --delete arch-jot::1_portal /home/jot/200g/source/1_portal/ --exclude=/*/target --exclude=/target --exclude=/output --exclude=/web-deploy --exclude=/setup

Q&A:
rsync: delete_file: unlink “…” failed: Permission denied (13)
– 要有x权限

kde4中Dolphin的回收站没了

手贱,Dolphin的回收站被我点没了。

以为很好恢复,配置里找了一圈,没找到。。。杯具么。。。

问谷歌,找到了解决方案:https://bbs.archlinux.org/viewtopic.php?id=74052

成功恢复!

知道了两件事,速记如下:
1、恢复方法:打开Dolphin地址栏(ctrl+l)输入”trash:/“,即是回收站。拖到”位置“书签,修改名字,恢复如初。
2、其他:kde4中dolphin的配置文件在 .kde4/share/config/dolphinrc 和 .kde4/share/apps/dolphin/。其他app类似。

无觅相关文章插件,快速提升流量