Try   HackMD

Git SOP on OpenDB

基本指令

創建 .git 目錄

  • 比方說我想對 ~/git_test 這個資料夾做版本控制

    • git init git_test/
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 設定 config 檔

    • git config --global user.name "Ashley"
    • git config --global user.email "user@gmail.com”
    • git config --global core.editor vim
  • 查看 config 檔

    • git config --list

Add

  • 新增 file1.txt & file2.txt

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • git status 查看目前 git 狀態

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

表示 file1.txt 與 file2.txt 尚未加入版本控制

  • git add [filename/directory]: 加入至暫存區
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    表示已加入,移除使用 git rm --cached [filename]

commit

  • git commit -m "描述"
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

查詢版本

  • 列出版本的詳細資料:git log
  • 列出所有的版本變化:git reflog
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

恢復版本

所做修改 (edit file2),且加入版本控制

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 檢視某個版本git checkout [版本號]

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    可以用 5048438 或是 HEAD~1: 概念有點像絕對地址跟相對地址

  • 檢視最新版本: git checkout master

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

確認恢復上一個狀態 reset

  • git reset 5048438
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 此時的狀態回復到 initial 的狀態,且 file2 的更改存在暫存區。

分支功能

建議寫某個功能時,都建立一個 branch,等到確定可用在 merge 到 master

建立分支

  • git branch [BranchName]
  • 建立分支,但所在分支不會改變

切換分支

  • git checkout [BranchName]

合併分支 (將某個 branch 合併到 master)

  • git checkout master
  • git merge [BranchName]
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

顯示所有分支

  • git log --oneline --all --graph
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    (我的被我搞得有點亂,但大致會得到這樣的畫面)