Git 筆記 (1-1) 基本指令操作

Git 筆記


Git 基本 command:

CommandDescription
git init建立 repository (檔案庫),相關資訊會存放在 ".git" 資料夾中
git add註冊檔案到 staging area,"git add ." 可用來註冊所有檔案
git status查看 staging area 的狀態
git commit將staging area 的檔案提交到repository
gitk查看提交的版本樹


Git 基本 command 使用範例:

1. 創建一個 GitTest 資料夾並切換到該資料夾下

$ mkdir GitTest
$ cd GitTest

2. 初始化 GitTest

$ git init

成功的話會出現 Initialized empty Git repository in...


3. 建立一個新檔案 HelloPy.py,並將 print ("Hello Python") 加入 HelloPy.py

$ touch HelloPy.py
$ echo 'print ("Hello Python")' >> HelloPy.py

4. 將加 HelloPy.py 入 staging area 並查看 staging area 的狀態

$ git add HelloPy.py
$ git status

5. 將staging area 的檔案提交到repository,這邊使用的格式為 git commit -m "說明" --author="操作者姓名<email>"

$ git commit -m "First commit" --author="ooxx<ooxx@gmail.com>" 

筆者測試這行指令在 windows 下是可執行的,但在 ubuntu 下會顯示錯誤

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

後續討論到 git config 時會再為大家做補充


6.查看提交的版本樹

呼叫 gitk

$ gitk

7. 修改提交時的資訊,這邊使用的格式為 git commit --amend -m "說明" --author="操作者姓名<email>"

$ git commit --amend -m "Amend" --author="xxxx<xxxx@gmail.com>" 

留言

熱門文章