2020年12月11日 星期五

常用到的 git command

1.  =====透過git server 下載Source Code ======
# git clone git@github.com:zlargon/git-test.git

2. ====== 上傳新增的檔案(上傳之後還要commit與push) =======
# git add aaa.c bbb.c
   ====== 上傳整個資料夾裡面東西(假設要add 資料夾 123) =======
#
git add --all 123


3. ====== 上傳修改的檔案,也就是commit 檔案(commit之後還要push才會真的上Server) =======
# git commit aaa.c bbb.c -m "Modify two files!"      (-m 後面帶入commit的原因,git log可以看到)


4. ====== 將commit的檔案,真正上傳到git Serve =======
# git push


5. ====== 查看歷來更改的log訊息 =======
# git log


6. ====== 查看歷來更改的log訊息,以及更改的檔案內容 =======
git log -p


7. ====== 查看某個commit的版本修改的內容(ex; commit abcdefghijk) ========
# git log -p abcdefghijk


8. ====== 查看此包Code目前的branch以及有哪些branch =======
# git branch -a

9. ====== 將被修改的檔案還原此次版本的內容 ======
git checkout -- file

10. ====== 將被刪除的檔案回復 ========
# git checkout file


11. ====== 切換到某個branch,ex: danny,並且更新本地檔案與git Server同步 =======
git checkout danny
# git pull

12. ====== 新增一個branch,名字為 danny =======
#
git checkout -b danny
# git push -u origin danny

13. ====== 打tag,V0.0.1版 =======
git tag -a V0.0.1 -m "V0.0.1"
git push origin 
V0.0.1

14. ====== 想要把git server上面,回復到前一版 =====
# git reset --hard HEAD~ (或是 git reset --hard HEAD~1)
# git push -f

15. ====== 刪除本地tag ======
git tag -d 標籤名

16. ====== 刪除遠端git server上面的tag ====
git push origin --delete tag 標籤名

17. ===== 已經git commit,但是還未push,想回復到前一版 ======
# git reset --soft HEAD^

18. ====== 回到特定 tag 版本 ====
# git checkout 00.03.03.03

19. ====== 刪除git上面的檔案/資料夾 =======
# git rm "file_name"  (刪檔案)
# git rm -r --cached "folder_name" (刪資料夾)

2020年11月17日 星期二

shell script 帶參數, 印出usage使用方式的程式框架

 撰寫Script常常會帶入參數,又需要當使用者沒有帶入參數時,要印出使用方法.

下面的程式框架是要求使用者帶入兩個參數,如果使用錯誤,則印出usage()告知使用者.

此檔案 test.sh實際做法如下:

#!/bin/sh

function usage()

{

    echo "test.sh.sh [arg1] [arg2]"

    echo "ex: test.sh 1 2"

}

if [ "$#" -lt "2" ]; then

    usage

    exit 0

fi

#If arg1 and arg2 exist, then do following thing...   


2020年10月30日 星期五

shell script 大寫轉小寫,小寫轉大寫

#大寫轉小寫
============= upper_to_lower.sh ================= 

value="$(echo $1 | tr '[:upper:]' '[:lower:]')"
echo $value

執行:
./upper_to_lower.sh  AA      ==>   aa



#小寫轉大寫
============= lower_to_upper_.sh ================= 

value="$(echo $1 | tr '[:upper:]' '[:lower:]')"
echo $value

執行:
./upper_to_lower.sh  aa     ==>   AA



2020年10月27日 星期二

Source Insight 無法加入 *.cc檔案

 遵照下面操作步驟,可以把*.cc檔案加入到目前Project


Options -> Document Options,然後在視窗上方 Document Type的下拉選項,選擇C++ Source File,右邊的File filter欄位,請加入 *.cc ,然後就可以選擇Close Button.














接著在右邊檔案列表的地方,按滑鼠右鍵,選擇 Synchronize Files

shell script if 判斷多個條件

 if判斷多個條件的寫法如下: (sh)

=================

#!/bin/sh
A=10
B=15

if [ $A = "10" ] && [ $B = "15" ]; then
    echo "A=10 and B=15"
fi

if [ $A = "10" ] || [ $B < $A ]; then
    echo "A=10 or B<A"
fi



2020年9月22日 星期二

Shell script使用for來parser以空白做間格的字串

 Shell script使用forparser以空白做間格的字串 (Bash)

 #!/bin/bash

package="111 222 333 555 666"

for p in ${package[@]}; do

    echo $p

done

 

實際執行結果,如下圖



2020年9月21日 星期一

cp: will not overwrite just-created

 今天 跑Script的途中,遇到一個問題 cp: will not overwrite just-created,而導致script停了下來

其發生主要的原因是,當我們 cp 或是 mv 兩個不同地方,卻是同樣的檔案名稱到同一個目錄底下

系統為了防止第二個文件去覆蓋第一個文件,所以報錯誤

 

今天遇到了,才知道會有這樣子的錯誤訊息,以上~


實際範例說明:  

有a, b, c三個資料夾,a與b資料夾內都有一個叫做file的檔案,接著我們故意一行指令同時複製a底下的file,與b底下的file到c資料夾,如下圖所示,就會出現此錯誤訊息!