Git常用命令(學習筆記)

2021-10-23 02:05:50 字數 1099 閱讀 8166

當你改亂了工作區某個檔案的內容,想直接丟棄工作區的修改時,用命令git checkout -- file

當你不但改亂了工作區某個檔案的內容,還新增到了暫存區時,想丟棄修改,分兩步,第一步用命令git reset head,就回到了上面,第二步按上面的步驟。

已經提交了不合適的修改到版本庫時,想要撤銷本次提交,參考版本回退,不過前提是沒有推送到遠端庫

一般情況下,你通常直接在檔案管理器中把沒用的檔案刪了,或者用rm命令刪了:

rm test.txt

這個時候,git知道你刪除了檔案,因此,工作區和版本庫就不一致了,git status命令會立刻告訴你哪些檔案被刪除了:

$ git status

on branch master

changes not staged for commit:

(use "git add/rm >

..." to update what will be committed)

(use "git checkout -

->

..." to discard changes in working directory)

deleted

: test.txt

no changes added to commit (use "git add" and/or "git commit -a")

現在你有兩個選擇,一是確實要從版本庫中刪除該檔案,那就用命令git rm刪掉,並且git commit

$ git rm test.txt

rm 'test.txt'

$ git commit -m "remove test.txt"

[master d46f35e] remove test.txt

1 file changed, 1 deletion(-)

delete mode 100644 test.txt

現在,檔案就從版本庫中被刪除了。

git 鼓勵大量使用分支:

廖雪峰

git常用命令學習筆記

1 初始化乙個git倉庫 git init2 新增檔案到git倉庫,可以反覆多次使用,新增多個檔案 git add3 完成,新增注釋 git commit4 要隨時掌握工作區的狀態,git status5 如果git status告訴你檔案被修改過,檢視修改的內容使用 git diff6 head指...

Git 常用命令學習筆記

case 1 cd alg ocr utils 在master git add 在master git commit m images enhancement 在master alg ocr utils git new text detect rule git checkout b new text...

學習筆記 git常用命令

1 安裝 apt get install git core2 新增公鑰 使用如下命令生成金鑰檔案 ssh keygen c 294154435 qq.com t rsa 會在使用者目錄 ssh 下建立相應的金鑰檔案 可以使用 ssh v git github.com 命令來測試鏈結是否暢通。3 全域...