2017年4月11日 星期二

Git commands

  • Settings
    • git config --global user.name "Your name"
    • git config --global user.email "Youremail@xxx.xx"
    • git config --global core.editor "vim"
  • Checking & Help
    • git config --list
    • git help
    • git help add
  • Create local repository and initial the project.
    • cd FirstApp
    • git init
    • git add * or git add *.java or git add AndroidManifast.xml
    • git add .gitignore
    • https://github.com/github/gitignore
    • git commit -m "Initial Project Version"
    • git status
    • change a file,  i.g AndroidManifast.xml
    • git diff  // diff the file in working sapce
    • git add AndroidManifast.xml
    • git diff --cached // diff the file in staged state
    • git commit -a -m "Change comment added 2"  
    • git add DeletedMe.txt
    • git rm -f DeleteMe.txt  // -f will remove from staged state and also delete file from workspace
    • git rm --cached DeleteMe.txt // it just remove from staged state, the file still exist
    • git mv DeleteMe.txt Delete.txt // rename the file name.
    • git log --pretty=oneline
    • git log --pretty=format:"%h : %an : %ar : %s" // abbreviation, author, time, comment
    • git log
    • git log -p - 2 // show last two changes
    • git log --stat
    • git log --since=1.w
    • git log --since="2014-04-12"
    • git log --author="Author name"
    • git log --before="2014-04-13"
  • Undo comment
    • git add DeleteMe.txt
    • git commit -m "Random Change"
    • git commit --amend // allow you to undo previous comment.
  • Un-staged the file
    • git add Delete.txt
    • git reset HEAD Delete.txt
  • Git, remote, Repositories, GitHub, Push, Pull, aliases and Tags
    • cd FirstApp
    • git init
    • git add .
    • git commit -m "First Project Version"
    • git remote add origin https://github.com/youraccount/your_project_on_git_hub
    • git push origin master  // then input the account and password on github
    • git remote -v
      • origin https://github.com/youraccount/xxx.git (fetch)
      • origin https://github.com/youraccount/xxx.git (push)
    • git fetch origin
    • git pull https://github.com/youraccount/xxx.git
    • git add .gitignore
    • git commit -m "Add .gitignore for Android"
    • git add Andoridmanifest.xml
    • git commit -m "Changed Android Manifest Comment"
    • git push
    • git remote -v 
      • origin https://github.com/youraccount/xxx.git (fetch)
      • origin https://github.com/youraccount/xxx.git (push)
    • git remote rename origin sf
    • git remote -v 
      • sf https://github.com/youraccount/xxx.git (fetch)
      • sf https://github.com/youraccount/xxx.git (push)
    • git tag  // to check all tag in current branch
    • git tag -a v0.2 -m "Version v0.2"
    • git show v0.2
    • git push sf v0.2   // push single tags onto github, you can check release tab to see the information on github websit.
    • git push sf --tags  // push all tags onto github
  • Create a short cut command
    • git config --global alias.co commit
    • git add .
    • git co -m "Demostrate Alias"
  • git clone 
    • cd google_pacman
    • git clone https://github.com/xxxxx/google_pacman.git
  • branch
    • git branch fix20          // create fix20 branch
    • git checkout fix20      // switch to fix20 branch
    • git checkout -b fix20  // create fix20 branch and switch to it
    • git checkout master    // switch to main branch 
    • git push origin fix20   // push the branch onto github, you can check branch tab on github website.
    • git checkout -b fix20 origin/fix20  // pull the fix20 branch from github
    • git branch  // check the branch status
      • fix20
      • *master
    • git branch --merged   // check merged branch
    • git branch --no-merged  // check unmerged branch
    • git branch -v
    • git merge fix20
    • git branch -d fix20 // delete fix20 branch, delete the merged branch
    • git branch -D fix20 // delete fix20 branch which is unmerged.
    • git push origin :fix20  // delete fix20 branch on github

  • git branch: check current local Repo branches
    i.e:
    $git branch
    master

  •  git branch -r : check remote repo branches
    i.e:
    $git branch -r
    origin/HEAD -> origin/master
    origin/cleanup
    origin/master

  • git checkout -b <local branch name> <remote branch name>
    i.e:
    $git branch -b cleanup origin/cleanup
    Use git branch to check current branch on your local repo 

  • git checkout <local branch name>: switch local branch
    i.e:
    $git branch
    *cleanup
    master

    '*' indicate which branch you are using
    $git checkout master $git branch cleanup
    *master
    Now you are using master branch.

2017年3月30日 星期四

2017年3月29日 星期三

如何在 Ubuntu 中自動掛載 virtualbox 的 Shared Folders

利用 Virtualbox 安裝 Guest OS 為 Ubutun 14.04 後,如何自動掛載 Shared Folders? PS: 要使用 Shared Folders 必須先安裝 Guest Additions。
  1. 設定 Shared Folders 為 Auto-mount, 當你設定為 Auto-mount後,預設載入點為 "/media/sf_[Folder Name]",但是你不是 root 或者 vboxsf 群族的使用者,沒有權限瀏覽這些目錄;所以必須把目前的使用者加入到 vboxsf 群組中,加入的方法可以使用下列指令,加入後必須先logout 再 login,完成後可以透過 id 指令檢查是否加入到 vboxsf 群組中。

  2. tmp@tmp-linux:~$ sudo gpasswd -a tmp vboxsf
    


  3. 修改 /etc/rc/rc.local,加入下列內容, Folder_Name 為利用 virtualbox 所設定的分享目錄名稱, your_mount_point 則為你像要掛載的路徑 例如: /home/userName/folderName,預設會是使 root 帳號,目前使用只可以瀏覽無法變更。

  4. mount -t vboxsf -o Folder_Name your_mount_point
    


  5. 修改 /etc/fstab,這個我沒有試過,請參考 How to mount a VirtualBox shared folder at startup?

Ubuntu 如何啟用,停用 root 帳號與切換為 root 使用者

Ubuntu 如何登入為ROOT使用者
Ubuntu 原本的 root 是預設尚未設定密碼(不是空白密碼), 第一次使用root的話使用sudo passwd root指令, 若之前尚未使用sudo執行其他指令, 此時一樣會提示你輸入你的使用者密碼(sudo確認身份用的).
當此密碼通過後, sudo會執行後面的指令, 也就是用root權限執行 passwd root(修改root密碼), 跟著系統提示輸入兩次root密碼後就將root密碼改成功了!

tmp@tmp-linux:~$ sudo passwd root
[sudo] password for tmp: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

以後若不想用 sudo 而想直接用 root 權限的話就使用 su - 切換進 root 身份即可

tmp@tmp-linux:~$ su -
Password: 
root@tmp-linux:~#

若要檢查 root 帳號是否有被啟動,可以下面指令查詢 如果是啟動的狀態第二欄位會顯示 P, 否則顯是為 L:
tmp@tmp-linux:~$ sudo passwd -S root
root P 03/27/2017 0 99999 7 -1  #如果是 P 為啟動狀態
或者 
root L 03/27/2017 0 99999 7 -1  #如果是 P 為停用狀態
若要停用 root 帳號 可以使用
sudo passwd -l root
或者
sudo passwd -p '!' root