2014年6月14日 星期六

使用git-svn解決無svn http server而上傳程式

欲在區網上做測試環境,但伺服器上svn db 沒有開svn server,只可以ssh,所以使用git-svn這個迂迴的方法上傳程式到伺服器上的svn db(因git可以走ssh)

外部ip:x.x.x.x
svn db和程式放在外部伺服器上(走file://)
內部ip:o.o.o.o
我能動的只有外部伺服器的家目錄,和ssh連線到外部ip

svn db: x.x.x.x/home/svn/my_project
live 程式:x.x.x.x/var/www
將svn db用git svn clone到自己家目錄:x.x.x.x/home/user/git-svn_test
$ git svn clone file:///home/svn/my_project git-svn_test
再用ssh將去連結自己家目錄下git-svn的專案,在內部伺服器上改程式後再push上去到外部伺服器的家目錄下

$ git remote add ssh://x.x.x.x:22/home/user/blog_workspace/git-svn_test

測試紀錄
mkdir svn_test git-svn_test git-ssh_test # svn_test是外部live程式,git-svn_test是外部ip家目錄程式(橋接用),git-ssh_test是內部ip的測試環境

$ svnadmin create /home/svn/my_project #產生測試專案

ps. 下面git-svn 是remote 的名字

git-svn 使用方法參考: http://blog.chhsu.org/2010/05/git-git-svn.html

※svn_test
$ svn checkout file:///home/svn/my_project svn_test
$ touch svn_test/index.html
$ cd svn_test/
$ svn add index.html
$ svn commit -m "svn hello world"

※git-svn_test( 在remotes/git-svn/master這branch工作 )
$ git svn clone file:///home/svn/my_project git-svn_test
$ git checkout remotes/git-svn/master  # 做這步才會使git-ssh_test push上來的資料更新內容,且在這個branch上git svn dcommit 到svn db 上
$ git svn dcommit  #推git-svn_test的內容到svn db上
$ git svn rebase # 更新檔案到svn db上最新的內容,類似svn update, git pull

※git-ssh_test(在 svn-ssh_branch 這branch工作)
$ git --bare init
$ git remote add git-svn ssh://x.x.x.x:/home/user/blog_workspace/git-svn_test # ssh://x.x.x.x:22:/home/user/blog_workspace/git-svn_test 也是錯的
$ git fetch git-svn
ssh: Could not resolve hostname x.x.x.x:: Name or service not known
fatal: The remote end hung up unexpectedly =>會出現這錯誤
$ git remote rm git-svn
正確作法:
$ git remote add git-svn ssh://x.x.x.x:22/home/user/blog_workspace/git-svn_test
$ git fetch git-svn
user@x.x.x.x's password:
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ssh://x.x.x.x:22/home/user/blog_workspace/git-svn_test
 * [new branch]      master     -> git-svn/master
$ git branch -a
  remotes/git-svn/master
$ git checkout -b svn-ssh_branch remotes/git-svn/master # 建立svn-ssh_branch
$ echo "test" >> index.html
$ git add .
$ git commit -m "git-ssh commit"
$ git push git-svn svn-ssh_branch:remotes/git-svn/master git push git-svn_remote svn-ssh_branch:master  #推內部ip的程式到外部家目錄下 => http://stackoverflow.com/questions/1519006/git-how-to-create-remote-branch
user@x.x.x.x's password:
Counting objects: 5, done.
Writing objects: 100% (3/3), 237 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://x.x.x.x:22/home/user/blog_workspace/git-svn_test
 * [new branch]      svn-ssh_branch -> remotes/git-svn/master
$ git pull git-svn remotes/git-svn/master:svn-ssh_branch git pull git-svn_remote master:svn-ssh_branch # 更新自git-svn上的程式
(不能pull試試把紀錄reset --hard到前面一點的紀錄,再pull)

錯誤:
...
 ! [remote rejected] svn-ssh_branch -> remotes/git-svn/master (branch is currently checked out)
...
http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked
解法:
在remote repository資料夾下這指令
$ git config --bool core.bare true
或是
http://www.cnblogs.com/abeen/archive/2010/06/17/1759496.html
这是由于git默认拒绝了push操作,需要进行设置,修改.git/config(倉庫git-svn_test的)添加如下代码:
    [receive]
    denyCurrentBranch = ignore
在初始化远程仓库时最好使用 git --bare init   而不要使用:git init
   (如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时,   如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上,  也即在远程仓库的目录下对应的文件还是之前的内容,必须得使用git reset --hard才能看到push后的内容. )

錯誤:
$ git svn dcommit
fatal: This operation must be run in a work tree
update-index --refresh: command returned error: 128
http://stackoverflow.com/questions/9262801/fatal-this-operation-must-be-run-in-a-work-tree
解法:
$ git config core.bare false
所以在git-svn推到svn db時需要再下這指令,git-ssh推到git-svn時要再度打開
還是出現這錯誤的話嘗試git reset --hard

結論:
svn db 有新紀錄要更新到git-ssh_test
git-svn_test$ git svn rebase
git-ssh_test$ git reset <較前面的commit_id> --hard
git-ssh_test$ git pull git-svn remotes/git-svn/master:svn-ssh_branch

更新程式從git-ssh_test到svn db
git-svn_test$ git config --bool core.bare true
git-ssh_test$ git push git-svn svn-ssh_branch:remotes/git-svn/master
git-svn_test$ git config core.bare false
git-svn_test$ git reset --hard
git-svn_test$ git svn dcommit
svn_test$ svn update


svn 遠端倉庫改網址
用$ svn info查URL版本庫根
$ svn relocate
未知命令: “relocate”
使用“svn help”得到用法。
原因:
svn版本太新 -version 1.8.9 (r1591380)
svn 1.8.6才有svn relocate,改用svn switch --relocate
http://stackoverflow.com/questions/617239/svn-switch-relocate-not-persisting
bear@s2:/home/www/dev/cakephp$ svn switch --relocate  http://svn.your_domain.com.cn:81/84/trunk http://svn.your_domain.com.cn/svn/84/trunk

我用的是git svn,要怎麼改呢?
http://stackoverflow.com/questions/268736/git-svn-whats-the-equivalent-to-svn-switch-relocate
https://git.wiki.kernel.org/index.php/GitSvnSwitch
1. Edit the svn-remote url URL in .git/config to point to the new domain name # url = http://svn.your_domain.com.cn/svn/84/trunk/www/as/cakephp
2. Run git svn fetch - This needs to fetch at least one new revision from svn! => 出現錯誤:
Authentication realm: <http://svn.your_domain:80> SVN Repositories
Password for 'bear': Can't locate Term/ReadKey.pm in @INC (you may need to install the Term::ReadKey module) (@INC contains: /usr/share/perl5/site_perl /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl .) at /usr/share/perl5/vendor_perl/Git.pm line 565.
解法:安裝perl 的Term/ReadKey
# cpan
cpan[1]> install Term::ReadKey
3. Change svn-remote url back to the original url # url = http://svn.your_domain.com.cn:81/84/trunk/www/as/cakephp
4. Run git svn rebase -l to do a local rebase (with the changes that came in with the last fetch operation)
5. Change svn-remote url back to the new url # url = http://svn.your_domain.com.cn/svn/84/trunk/www/as/cakephp
6. Run git svn rebase should now work again! =>出現錯誤: Unable to determine upstream SVN information from working tree history
( git reset --hard到之前的版本仍無效)
使用其他方法:
重新git svn clone 到新的資料夾,
然後參考 "[git] 查歷史紀錄 ( git常見問題 )" 把diff檔取出來然後apply回去
git apply出現錯誤
$ git apply ~/tmp.diff
error: cannot apply binary patch to 'app/webroot/css/images/images/album-b.jpg' without full index line
error: app/webroot/css/images/images/album-b.jpg: patch does not apply
解法:
編輯diff檔,把新增的圖檔那幾行刪掉再apply
cakephp記得再把tmp權限改成777

svn relocate出現錯誤:
The repository at 'https://new-repository/newpath/folder' has uuid 'd3b83275-bf16-aa42-9467-f8a402003233', but the WC has '30e22be1-af51-d84d-ad8f-d4e8545a4735'
http://stackoverflow.com/questions/3565284/problem-trying-to-relocate-wc-to-new-repository
原因:
relocate只能在你的svn庫移動後且svn沒有任何改變才能relocate ( You can not do relocate to a new repository, you need to delete your working copy and do a clean checkout.
Relocate can only be used if a repository has been moved unchanged to a new server or the server has got a new name. )

2014年6月9日 星期一

iso製作usb安裝

方法一
(OS: ubuntu 14.04 =>bs要用2048不能用2m,/dev/sdb1 用$df -h 看你的usb是哪個,用容量看)
$ sudo dd if=OS.iso of=/dev/sdb1 bs=2048

方法二
$ cat debian.iso > /dev/sdc; sync

方法三
http://unetbootin.sourceforge.net/
下載 unetbootin-linux-608.bin 檔後
($ sudo aptitude install p7zip-full  # 需安裝p7zip-full )
$ chmod +x ./unetbootin-linux-608.bin
$ sudo ./unetbootin-linux-608.bin
(重開機,還有錯,應該是pc問題)


重新格式化usb
https://bbs.archlinux.org/viewtopic.php?id=127583
$ sudo umount /dev/sdb
( $ apt-cache search gparted #安裝gparted )
$ sudo gparted /dev/sdb => 會打開GUI界面,usb需重新插拔


2014年6月4日 星期三

virtualbox心得

NB作業系統(Arch Linux),接無線網路
灌好virtualbox後
使用橋接模式雖然可以ssh到同網域,但是看起來頻寬不足,apt-get update時會卡住,還不確定怎麼解決。所以改用NAT模式 =>請嘗試使用有線網路,不要用無線網路。source.list修改國內網站(2014/11/26)

https://forums.virtualbox.org/viewtopic.php?f=8&t=55766

打開VM後(可以在vm開機後設定) => 裝置 => Network => 網路設定 =>連接阜轉送(按鈕) => 新增下面設定
名稱:ssh
協定:TCP
主機:127.0.0.1
主機連接阜:2222
客體IP:10.0.2.15
客體連接阜:22
然後在NB上開終端機輸入指令
$ ssh -p 2222 root@127.0.0.1
就能連結到NAT的VM上面了

理論上區網其他電腦裡面的vm也能這樣連,作者和我都沒試過
$ ssh -p 2222 root@192.168.21.121

VirtualBox 錯誤訊息 VT-x/AMD-V 硬體加速在您的系統不可用
http://notepad-of-steven.blogspot.com/2015/08/0022-virtualbox-vt-xamd-v.html
先下載檢測工具 LeoMoon CPU-V 
見查後發現是如下圖

這個結果表示您的系統支援 VT-x,但是該設定並沒有被開啟。因此,您需要到電腦的 BIOS 去確定您的電腦是否有開啟。

BIOS 設定
在 Intel 電腦的 BIOS 中,(有可能是在 Advanced,或者 CPU Configuration 裡面) 找一個名稱如 Intel Virtual TechnologyVirtualization 之類的選項,如果原設定是 Disabled,則將它改為 Enabled 之後再儲存,離開 BIOS 重開機就可以了。
在 AMD 電腦的 BIOS 中,(有可能是在 Advanced,或者 CPU/System Configuration 裡面) 找一個名稱是 SVM Mode 或 Virtualization Technology 或 Virtualization 之類的去改為 Enabled,儲存之後離開 BIOS,再重開機就可以了。
如圖


設定完BIOS後重開機再用 LeoMoon CPU-V 檢測一次結果會是






svn 常見問題

取回某版本的某支檔案
http://stackoverflow.com/questions/4218859/how-do-i-view-an-older-version-of-an-svn-file
$ svn update -r 666 file => 不能這樣寫,倒回舊的再修改後會變成要你svn update成最新的才能commit上去,變得不能revert某支檔案再修改
$ svn cat -r 666 file > file => 這樣就能revert檔案到某版本再繼續改後commit

SVN + private key 設定

SVN -> settings -> Network -> SSH client:

example:

"C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe" -i D:\xxx.ppk


使用
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Pageant
如果要連多個伺服器時,可設定多個key,才不用在svn設定裡一直換key
但有可能會跟VPN打結

查兩個revisions之間的log
$ svn log -r 20:30 #查20~30之間的log
參考資料:http://stackoverflow.com/questions/167371/how-do-i-see-what-files-were-changed-between-2-revisions

忽略資料夾和資料夾下某些檔案
$ svn revert -R . #回覆最原始版本,等同 git reset --hard,最後的點(.)很重要
$ cd app/tmp/
$ svn propset svn:ignore "*" . --recursive  # 不追蹤tmp資料夾,必須移到tmp資料夾下操作
$ cd app/Config/
$ svn propset svn:ignore "database.php
> core.php" . # 不追蹤database.php和core.php,使用雙引號和enter送成兩行,必須在該資料夾下操作
也可以到該資料夾下用下面這指令更改要ignore的檔案
$ svn propedit svn:ignore .
最後記得svn commit
$ svn pget svn:ignore -R # 看svn下有哪些檔案被ignore



設置svn預設編輯器
在 svn propedit svn:ignore .  指令中會打開編輯器,如果要更改回vim則
在~/.bashrc(或 ~/.bash_profile )加入:
export SVN_EDITOR=vim

2014年5月21日 星期三

debian安裝firefox 繁體中文

# aptitude purge iceweasel #先移除盜版firefox
# aptitude install firefox
# aptitude install firefox-l10n-zh #會變簡體中文
打開firefox ,用google搜尋" linux firefox 29 tradition chinese "
Traditional Chinese (zh-TW) Language Pack 29.0
https://addons.mozilla.org/zh-tw/firefox/addon/traditional-chinese-zh-tw-l/
把這個套件加到firefox上

登出後登入

firefox變繁體中文

chrome 英文版變中文
登入google帳號
設定=> 搜尋lang=> 把預設語言設成中文(要等一陣子才會出現)
重啟電腦

2014年4月9日 星期三

安裝debian server

RAM: 2G
硬碟:8G

欲安裝的軟體:
screen, sudo, vim, git, mysql( mysql-server, mysql-client,  ),

安裝sudo
http://sharadchhetri.com/2013/08/07/sudo-command-not-found-debian-7/
$ apt-get update
$ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
$ sudo apt-get install vim
bash: sudo: command not found
$ su -
# apt-get install sudo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  sudo
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/851 kB of archives.
After this operation, 1,885 kB of additional disk space will be used.
Media change: please insert the disc labeled
 'Debian GNU/Linux 7.4.0 _Wheezy_ - Official i386 CD Binary-1 20140208-12:25'
in the drive '/media/cdrom/' and press enter => 要你插光碟
解法:
http://askubuntu.com/questions/236288/apt-get-asks-me-to-insert-cd-why
sudo gedit /etc/apt/sources.list
把這行註解掉:
# deb cdrom:[Ubuntu 12.10 _Quantal Quetzal_ - Release amd64 (20121017.5)]/ quantal main restricted
然後別忘了: sudo apt-get update
就能 # apt-get install sudo 了

user_name@linux:~$ sudo apt-get install vim
出現錯誤:
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for user_name:
user_name is not in the sudoers file.  This incident will be reported.
解法:
用root 編輯這個檔案:
# vi /etc/sudoers
加入這一行:
user_name ALL=(ALL:ALL) ALL
user_name就能使用sudo安裝套件了

vim 沒highlight
在~/.vimrc裡面加入這行: syntax on
或將 /etc/vim/vimrc 的" syntax on 註解拿掉

安裝mysql
http://ariejan.net/2007/12/12/how-to-install-mysql-on-ubuntudebian/
$ sudo apt-get update
$ sudo apt-get dist-upgrade  # 什麼是apt-get dist-upgrade
※ upgrade: 系統將現有的 Package 升級, 如果有相依性的問題, 而此相依性 需要安裝其它新的 Package 或 影響到其它 Package 的相依性時, 此 Package 就不會被升級, 會保留下來.
※ dist-upgrade: 可以聰明的解決相依性的問題, 如果有相依性問題, 需要 安裝/移除 新的 Package, 就會試著去 安裝/移除 它. (所以通常這個會被認為是有點風險的升級)
$ sudo apt-get install mysql-server mysql-client  # 我安裝時他就提示要我設置mysql的root密碼,故不用另外用指令設置了
如果裝好mysql和apache後需要裝php5-mysql才能讓php用mysql( mysql, mysqli 擴展 )
$ sudo apt-get install php5-mysql

安裝php
$ sudo apt-get install php5  # 網路上找到的都要安裝 libapache2-mod-php5 ,但php5安裝完就有裝libapache2-mod-php5了
$ dpkg --get-selections | grep php
libapache2-mod-php5                             install
php5                                            install
php5-cli                                        install
php5-common                                     install

新增資料庫
# mysqladmin create xxx
錯誤訊息:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
解法:
照這篇改密碼後就可以了
http://magicsun.pixnet.net/blog/post/25768313-mysqladmin%3A-connect-to-server-at-'localhost'-failed-%E8%99%95%E7%90%86
雖然改的密碼前後都一樣( 我原本mysql -u root -p 可以登入 ),估計是mysql> FLUSH PRIVILEGES; 的關係


2014年4月7日 星期一

KDE常見問題

因為GNOME的cinnamon在雙螢幕時無法像zbar或UltraMon 一樣底下有兩個工作列( dual monitor panel ),所以改用KDE plasma(雖然KDE也是有一堆不習慣的缺點... 用linux辦公深深體會到linux is free if your time is no value)
ex.
1. panel 在左右時會浮在視窗上面無法固定
2. 桌面沒有東西,需要新增一個資料夾的panel,然後將這個panel指到桌面資料夾去,而且這個panel還不能調整大小
3. 在左下角K中搜尋程式,中文會找不到,只能打英文
KDE Plasma上仍使用cinnamon 軟體的軟體:
終端機 - gnome-terminal
File manager - nemo

用了KDE遇到的問題:
skype選取聯絡人時顏色無法閱讀
解法:
1. 編輯 ~/.config/Trolltech.conf
2. 在 [Qt%20Plugin%20Cache%204.8.false] 區間內找到這行:
usr\lib\kde4\plugins\styles\oxygen.so=0, 1, , 2014-02-01T10:37:25
然後把他刪掉
3. 重啟skype
(重開機後就無效了,改用下面方法)
http://ubuntuforums.org/showthread.php?t=2098775
for me, only the following actions made stable effect:
1. install kde-config-gtk gtk2-engines-oxygen:i386
2. go to Sytem Settings -> Application Appearance ( KDE: K=>設定=>系統設定=>應用程式外觀 )
a. colors - select Oxygen Gold ( 顏色=>機制=>選Oxygen Gold => 套用 )
b. GTK+ appearance - select oxygen-gtk  ( 左邊那個GTK分頁 )

KDE更改預設file manager:
http://ubuntuforums.org/showthread.php?t=893591&p=5615038#post5615038
expand KDE Components -> File Associations -> expand Inode -> Directory
Then move Konqueror above Dolphin in the Application preference order, apply

在桌面新增gnome-terminal捷徑(因為konsole的screen被選取標題的會閃爍)
~/桌面 $ ln -s /usr/bin/gnome-terminal

gnome-terminal 在 KDE 桌面啟動時會自動縮小
http://blog.roodo.com/rocksaying/archives/25394946.html
目前在 KDE 下解決 gome-terminal 縮小的方法是利用 KDE 的「視窗行為」微調。從「系統設定」/「視窗行為」/「視窗規則」(System Settings/Window Behavior/Window Rules)頁面,增加一條規則,其內容如下列:
※ 視窗比對 - 「視窗類別」,「完全符合」: gnome-terminal。
※ 大小與位置 - 勾選「遵循位置限制」,「強制」,「否」。 ("Obey geometry restrictions", "Force", "No")

Kde 不要透明=>左右無解,需換桌面主題=>放棄
https://forum.kde.org/viewtopic.php?f=67&t=94807 (未試)
換主題需清cache => delete the entire /var/tmp/kdecache-$USER/ directory
http://forum.kde.org/viewtopic.php?f=17&t=89913  (未試)
換主題:
K->Settings->System Settings->Workspace Appearance->Desktop Theme->Details.
Select Panel Background and choose "file." Then select your new panel-background.svgz image.
I chose /usr/share/kde4/apps/desktoptheme/default/opaque/widgets/panel-background.svgz

讓kde plasma左右兩視窗工作列taskbar只顯示在同一個螢幕的面板上
在”工作管理員”元件(需在面板上新增工作管理員元件)上點右鍵=>工作管理員設定=>一般=>過濾器=>勾選”只顯示目前螢幕上的工作”和”只顯示目前活動裡的工作”

KDE桌面上的那块桌面图标面板怎么调出来?
http://www.guokr.com/question/354783/
桌面點右鍵 => 新增元件 => 選”資料夾” => 新增後點元件設定圖示 => 位置 => 顯示桌面資料夾

KDE 4 滑鼠單擊啟動改成雙擊啟動 
左下角應用程式選單->應用程式->設定->系統設定->輸入裝置->滑鼠->「點兩下開啟檔案或目錄」

安裝新酷音詞庫
https://github.com/chewing/chewing-utils
$ wget https://github.com/chewing/chewing-utils/archive/master.zip
$ unzip master.zip
$ cd chewing-utils-master/hash-editor/
$ make
$ cd src
$ ./che  #可以把他建立連結到桌面
(後來發現不用這麼麻煩,新酷音新增詞庫,你打好字把他選好後enter,他就會自動記憶了)

延長螢幕變暗時間
K => 搜尋 powerdevil ( 省電模式 )

chrome和firefox在linux按backspace無法上一頁
1. 使用alt + <- 上一頁  和 alt+->下一頁
2. chrome安裝套件: Backspace As Back/Forward for Linux
3. firefox
    a. 開新分頁網址列打上: about:config
    b. 搜尋"browser:backspace_action",将其值由2 修改成0 即可