GIT - 常用基本指令


== 帳號設定 ==

# 設定git 帳號跟email
# 可以在特定專案底下設置
$ git config user.name "name" $ git config user.email "email"

# 也可以套用在系統全部套用設定
$ git config --global user.name "name" $ git config --global user.email "email"

== Branch 操作 ==

# 切換並同時建立以當下為基礎的branch
$ git checkout -b "new branch name"

# 列出目前local有使用過的branch,以及目前位於哪個branch $ git branch

# 列出所有的branch $ git branch -a # 列出 remote的branch $ git branch -r

# 刪除 remote的branch
$ git push origin --delete <branchName>
or
$ git push origin :<branchName>

# 刪除本地的branch
$ git branch -d <branchName>

# 強制刪除本地的branch
$ git branch -D <branchName>


== commit 操作 ==


# 修改上一筆commit 訊息
$ git commit --amend


== 檔案 操作 ==

# 還原file至修改前的狀態 $ git checkout <filename> # 把檔案暫存到staging裡,準備commit $ git add <filename> # 把所有動過或新增的檔案都暫存到staging裡 $ git add -a # 顯示目前branch的檔案狀態 $ git status # 顯示所有log $ git log # 顯示倒數最後n筆log $ git log -n <筆數> # 將staging裡的檔案都commit $ git commit # 將staging裡的檔案都commit,並直接寫訊息 $ git commit -m <message> # 將目前local有commit過的更新至remote上的branch $ git push origin <BranchName> # 將local更新至跟remote端的狀態 $ git pull --rebase # 還原至HEAD的上一版,並且修改過的檔案都捨棄 $ git reset --hard HEAD^ # 還原至HEAD的上一版,但有動過的檔案都保留下來 $ git reset HEAD^ # 把目前有動過的都先丟到stash裡 $ git stash # 取出stash裡最新的一筆,並從stash移除這筆紀錄 $ git stash pop # 顯示stash裡所有筆數紀錄 $ git stash list # 取出最新的一筆 stash 暫存資料,但stash裡的資料不會移除 $ git stash apply # 清空stash資料 $ git stash clear



留言

這個網誌中的熱門文章

devstack安裝all in one openstack(pike)

Python - 計算特定目錄底下的檔案以及目錄數量

利用ATOM 編輯器在Windows開發PHP