search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[Git] Basic Command | Calos's Blog

# 設定個人資訊 (這些資訊會顯示在commit log上)
git config --global username "your name"
git config --global email "your E-mail"

#------------------------------[init]-----------------------------------
# 切換到自己的專案目錄
cd my_project

# 管理初始化
git init


#------------------------------[add]----------------------------------
# 新增檔案
git add (file name)

# 將當前目錄下的所有檔案及目錄加入管理
git add .

# 將指定子目錄下的指定檔案加入管理
git add dir_name/file_name

# 將指定子目錄下的所有檔案加入管理
git add dir_name/.

# 新增修改過的檔案 (兩者皆可)
git add -u
git add modifyfile


#-------------------------------[commit]----------------------------------
# commit並添加註解
git commit -m "commit message"

# 自動add修改過的檔案(不包含未納管的檔案)並commit (會開啟editor,需要寫commit massage)
git commit -a

# 同上,差異在於commit massage直接寫在-m後面,並不會開啟editor
git commit -a -m "commit message"

# -v 可以看到檔案哪些內容有被更改
git commit -a -v


#-------------------------------[branch]----------------------------------
# 列出現有branch
git branch

# 列出所有branch
git branch -a

# 新增branch
git branch (branch name)

# 從master新增branch
git branch test-branch master

# 刪除branch
git branch -d (branch name)

# 強制刪除branch
git branch -D (branch name)

# 重新命名branch (當前branch為old branch時可忽略參數old branch name)
git branch -m (old branch name) (new branch name)

# 切換至指定branch
git checkout (branch name)

# 將指定的branch與當前branch合併
git merge (branch name)

#-------------[push、pull、clone、remote(以girhub為例)]-------------
# 提交變更至git server
git push [email protected]:(user name)/(project name).git

# 提交指定branch的變更
git push [email protected]:(user name)/(project name).git (branch name)

# 刪除git server上的branch(下列兩種方式皆可)
git push [email protected]:(user name)/(project name) .git :(branch name)
git push origin --delete (branch name)

# 檢查git server有無較新的變更,並拉下來更新本機的檔案(未指定remote+branch name則對目前branch進行作業)
git pull (remote) (branch name)

# 將該專案資料夾從git server拉下來
git clone [email protected]:(user name)/(project name).git

# 新增遠端名稱
git remote (remote name) [email protected]:(user name)/(project name).git

# 顯示現有remote清單
git remote -v

# 將project上傳到指定的remote
git push (remote name)

# 將project裡指定branch的上傳到指定的remote
git push (remote name) (branch name)
example:
git remote origin [email protected]:athlon20147/myproject.git //remote name : origin
新增好remote後,以下兩行功能相等
git push [email protected]:athlon20147/myproject.git
git push origin

-------------------------------[other]----------------------------------
# 檢視變更紀錄
git log

# 還原已經commit刪除的檔案
git checkout ^ -- 
ex: git checkout b05128e3ebd4f38c317f066d679aee21c7d3af65^ -- config/ldap-sample.php


熱門推薦

本文由 caloskaoorg 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦