1. 程式人生 > >學習筆記(楚才國科)

學習筆記(楚才國科)

git的基本命令: 把一個檔案放到Git倉庫只需要兩步: 1.git add file 2.git commit -m “explain”

檢視當前倉庫的狀態: git status 分三種情況 1.倉庫檔案沒有改動,沒有變化 $ git status

On branch master

nothing to commit, working directory clean

2.倉庫檔案有變動,1.例如你修改了檔案的內容,需要commit 2.你新增的新的檔案需要commit

On branch master

Changes not staged for commit:

(use “git add …” to update what will be committed)

(use “git checkout – …” to discard changes in working

#

modified: s.txt

# no changes added to commit (use “git add” and/or “git commit -a”)

很明顯修改了s.txt的內容。

On branch master

Untracked files:

(use “git add …” to include in what will be committed)

#

status.txt

nothing added to commit but untracked files present (use “git add” to track) 沒有跟蹤的檔案,status.txt是先新增的檔案

對比檔案修改和修改之前的差異內容 git diff file

版本回退(註釋很重要) 1.檢視所有版本資訊 git log

2.回退到上一個版本 上一個版本就是HEAD^,上上一個版本就是HEAD^^,當然往上100個版本寫100個^比較容易數不過來,所以寫成HEAD~100 git reset –hard HEAD^ git reset –hard 版本號

撤銷修改 當你改亂了工作區某個檔案的內容,想直接丟棄工作區的修改時,用命令git checkout – file 當你不但改亂了工作區某個檔案的內容,還新增到了暫存區時,想丟棄修改,分兩步,第一步用命令git reset HEAD file,就回到了場景1,第二步按場景1操作。

刪除一個檔案 git rm file 用於刪除一個檔案

合併分支: 檢視分支:git branch

建立分支:git branch

切換分支:git checkout

建立+切換分支:git checkout -b

合併某分支到當前分支:git merge

刪除分支:git branch -d