Git 版本控制:利用 git reset 恢復檔案、暫存狀態、commit 訊息

這次來介紹一下 git reset 的用法,為什麼會介紹這指令呢?因為今天想要看專案狀態,用 git status 觀看,發現被我玩爛了,所以出現了底下錯誤訊息:

$ git status
error: bad index file sha1 signature
fatal: index file corrupt
解決此問題非常簡單,要先刪除 index 檔案,請先砍掉

.git/index,恢復此 index 請用

git reset
這行指令相當於

git reset –mixed HEAD,或者是可以用 git read-tree 來取代 git reset,當然 git reset 不只是有這功能而已,假如您已經建立了 commit 訊息,也可以將此訊息拿掉,重新在 commit,或者是您修改過的檔案在暫存區,git 也可以幫您恢復到未暫存,或者是不想要這次的修改,也可以恢復到未修改的檔案喔。

取消已經暫存的檔案 假如我們有兩個檔案需要 commit,但是不小心按到 git add * 全部加入到暫存區,那該怎麼恢復呢?

# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       modified:   Makefile
#       modified:   user/easy_setup/easysetup.h
#
上面是以經在暫存區裡面等待被 commit 檔案(

Changes to be committed),大家可以看到括號裡面有提示如何拿掉 (use “git reset HEAD …” to unstage),所以我們下:

git reset HEAD user/easy_setup/easysetup.h
之後會看到 『

user/easy_setup/easysetup.h: locally modified』此訊息,這時候在用 git status 看狀態

# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       modified:   Makefile
#
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#
#       modified:   user/easy_setup/easysetup.h
#
[Read More]

Git 版本控制: 「You have some suspicious patch lines」

相信大家對 Git 並不陌生,這次在升級 Moztw 的討論區,從 3.0.5 升級到 3.0.7 p1,過程由其他 Moztw 成員升級,我在將最後程式 commit 到 github,因為兩個版本差異性很大,所以有新增多個檔案,commit 過程出現了錯誤訊息:「You have some suspicious patch lines」,這是因為 git 會檢查每行程式碼最後是否有多餘空白或者是 Tab 按鍵,為瞭解決此問題,可以去修改 .git/hooks/pre-commit,將底下程式碼: if (s/^\+//) { $lineno++; chomp; if (/\s$/) { bad_line("trailing whitespace", $_); } if (/^\s* \t/) { bad_line("indent SP followed by a TAB", $_); } if (/^([<>])\1{6} |^={7}$/) { bad_line("unresolved merge conflict", $_); } } 改成: if (s/^\+//) { $lineno++; chomp; # if (/\s$/) { # bad_line(" [Read More]

[C/C++] cstring (string.h) 函式:strcat, strncat, strcmp, strncmp

串接函式 strcat strcat 此函式用來連接兩字串合併成單一字串,直接看底下範例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /* strcat example */ #include <stdio.h> #include <string.h> int main () { char str[80]; strcpy (str,"these "); strcat (str,"strings "); strcat (str,"are "); strcat (str,"concatenated."); puts (str); return 0; } output: 1 these strings are concatenated. 看一下 strcat 原始碼: 1 2 3 4 5 6 7 8 9 char * strcat(char * __restrict s, const char * __restrict append) { char *save = s; for (; *s; ++s); while ((*s++ = *append++)); return(save); } 設定指標 save 成 source,再將 s 指標指向最後,接下來根據 append 字串一個一個往後串接,直到碰到 \0 終止 while 迴圈,最後在將指標 *save 回傳即可。 [Read More]

[C/C++] cstring (string.h) 搜尋函式:strstr, strchr

這次介紹 C 語言常用 string 函式:strstr,主要是針對兩個輸入參數做比對,Parameters 1 是輸入字串,Parameters 2 是找尋字串,strstr 會先將頭一次比對成功的 pointer 回傳,也就是如果要找尋 appleboyappleboy 字串中的 boy,函式會回傳第一次比對成功的 boy pointer,而並非回傳最後一個比對到的,底下是一個參考範例: strstr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* strstr example */ #include <stdio.h> #include <string.h> int main () { char str[] ="This is a simple string"; char * pch; /* 找尋 simple 字串 */ pch = strstr (str,"simple"); /* 將 simple 換成 sample */ strncpy (pch,"sample",6); puts (str); return 0; } 看一下 Kernel 原始檔案,strstr 函式: [Read More]

[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux

Windows C# C# 比較字串 MSDN 比較字串 Request.Form Collection Request Query String / Form Parametrs ASP.NET QueryString Usage Using include files with ASP.NET html [將所有 的內容包到一個 中][7] apache Fixing mod_rewrite and .htaccess on GoDaddy Hosting javascript jQuery Week Calendar Javascript: reference the parent window from a popup How to get and set form element values with jQuery How to check and uncheck a checkbox with jQuery Loop through parameters passed to a Javascript function perl-completion. [Read More]

[Kernel Driver] 撰寫簡易 Timer 機制

在底層 Linux Kernel 提供了時序(timing)機制,方便驅動程式設計者所使用,核心是依據硬體發出的『計時器中斷』來追蹤時間的流動狀況。我們可以依據 HZ 的值來設計 Delay 機制,讓驅動程式可以每隔固定一段時間啟動或者是發出訊號,也可以利用 Timer 來讓 LED 閃爍變化,在介紹 Timer API 之前,可以先參考 Linux Kernel: 簡介HZ, tick and jiffies 這篇文章,瞭解一些相關名詞,舉例:如果想知道一秒後的 jiffies 時間,可以寫成底下: #ifdef CONFIG_BMA150_TIMER #include #endif j = jiffies; /* 一秒之後 */ stamp_1 = j + HZ; /* 半秒之後 */ stamp_1 = j + HZ/2; /* 20秒之後 */ stamp_1 = j + 20*HZ; Timer API 用法 筆記一下自己在寫 BOSCH Sensortec 三軸加速偵測器(BMA150 Sensor) Driver 的時候,遇到底層要回報 input event X,Y,Z 到 Android HAL(Hardware abstraction layer),所以利用 Timer 的機制定時 report 給 Android。 首先宣告: [Read More]

[Linux Kernel] 簡單 hello world: License and Module 介紹(part 3)

在 Kernel 2.4 或以上版本,在編譯模組完成,要進行 load module 之前,你會發現底下訊息: # insmod hello-3.o Warning: loading hello-3.o will taint the kernel: no license See http://www.tux.org/lkml/#export-tainted for information about tainted modules 很顯然這訊息是要您在 kernel module 裡面加上版權宣告,例如:"GPL","GPL v2"…等來宣告您的 module 並非 open source,利用 MODULE_LICENSE() 巨集來宣告程式 License,同樣的,可以用 MODULE_DESCRIPTION() 來描述此模組或者是 Driver 的功用跟簡介,以及用 MODULE_AUTHOR() 來定義此模組作者,這些巨集都可以在 linux/module.h 裡找到,但是這些並非用於 Kernel 本身,如果大家想看範例程式,可以到 drivers/ 資料夾底下觀看每一個 Driver 程式,底下是簡單 hello world 範例: #include /* pr_info所需 include 檔案*/ #include #include /* 所有 module 巨集需要檔案*/ #include static int __init hello_init(void) { pr_info(" [Read More]

[高雄美食]道明中學武廟路好吃愛嬌姨臭豆腐

IMG_1290

我相信在高雄要吃到好吃的臭豆腐,無非就是豪記臭豆腐,大家可以參考懶喵兒滴窩:『[高雄-三民]豪記臭豆腐王【港式臭豆腐專賣店】 (新址)』,但是這次要來介紹也許在高雄比較少人知道的路邊攤臭豆腐,它位於高雄市武廟路上一間不起眼的臭豆腐,道明中學對面巷子走進去接到武廟路就可以吃到了,營業時間是下午15:30~19:40,時間不長,但是大排長龍阿,想要去吃的,最好不要挑晚餐時間,因為自己那個時間去吃,至少等了半小時。

[Read More]

[Linux Kernel] 撰寫 Hello, World module: The __init and __exit Macros (part 2).

再看此篇之前,可以先閱讀作者先前寫的:『[Linux Kernel Driver] 撰寫簡單 Hello, World module (part 1).』,今天要介紹 Driver 的 init module 區別,在 Kernel 2.4 版本,您可以自行定義 init 跟 cleanup 函式,他們不再被個別稱為 init_module() 和 cleanup_module(),現在都使用 module_init() 和 module_exit() 兩大巨集,這兩函式被定義在 linux/init.h 檔案裡面,所以在寫程式務必將其 include 喔,另外一個核心模組(MODULE_LICENSE),用於讓核心知道此模組遵守自由授權條款,若沒這項宣告,核心會跟您抱怨的喔,底下為範例: #include /* pr_info所需 include 檔案*/ #include #include /* 所有 module 需要檔案*/ #include MODULE_DESCRIPTION("Hello World !!"); MODULE_AUTHOR("Bo-Yi Wu "); MODULE_LICENSE("GPL"); static int __init hello_init(void) { pr_info("Hello, world appleboy\n"); pr_info("The process is \"%s\" (pid %i)\n", current->comm, current->pid); return 0; } static void __exit hello_exit(void) { printk(KERN_INFO " [Read More]

ProFTPD UseEncoding 繁體中文亂碼解決 Localization

Proftpd ProFTPD 一直都是我最喜歡使用的 FTP 伺服器,設定方式簡單淺顯易懂,最近在用 PSPad 寫程式,發現使用內建 FTP 功能時候,連不上 FreeBSD 架設的 ProFTPD,連線過程出現許多亂碼,所以造成 PSPad 斷線出現錯誤,解決方式就是利用 mod_lang 模組,設定 UseEncoding 讓系統可以顯示 Big5 中文編碼,FreeBSD Ports 請勾選

[X] NLSUOTA Use nls (builds mod_lang)
自行編譯請按照底下步驟
./configure --enable-nls
make
make install 

UseEncoding 設定

Syntax: UseEncoding on|off|local-charset client-charset
Default: None
Context: "server config", , 
Module: mod_lang
Compatibility: 1.3.2rc1
在 1.3.2rc1 版本之後才有支援,請複製底下設定,貼到 proftpd.conf
# 简体中文環境
UseEncoding UTF-8 GBK
# 繁体中文環境
UseEncoding UTF-8 Big5
Reference:

ProFTPD module mod_lang centos上解決proftp中文亂碼問題