基於上面的圖片,咱們來了解一些概念node
.git
文件git status
changes not staged for commit
- 表示得大概就是工做區有該內容,可是緩存區沒有,須要咱們git addchanges to be commit
- 表示文件放在緩存區了,咱們須要git commitnothing to commit,working tree clean
- 這個時候,咱們將本地的代碼推送到遠端便可git branch
git branch -r
git branch -a
git checkout <branch-name>
git checkout -b <branch-name>
git branch -d/-D <branch-name>
git merge <branch-name>
git branch -v
git push origin -d <branch-name>
或git push origin :<brnach-name>
git brnach -m <oldbranch-name> <newbranch-name>
git checkout -b 本地分支名 origin/遠程分支名x
或git fetch origin <branch-name>:<local-branch-name>
git fetch
git pull
git checkout -- <file>
git reset HEAD <file>
git reset --(soft | mixed | hard ) < HEAD ~(num) >
使用場景:
場景1:當你改亂了工做區某個文件的內容,想直接丟棄工做區的修改時,用命令git checkout -- file
。git
場景2:當你不但改亂了工做區某個文件的內容,還添加到了暫存區時,想丟棄修改,分兩步
第一步:用命令git reset HEAD <file>
,就回到了場景1;
第二步:按場景1操做。緩存
場景3:已經提交了不合適的修改到版本庫時,想要撤銷本次提交,參考版本回退一節,不過前提是沒有推送到遠程庫。fetch
git diff
git diff -- cached
git diff <commit ID> <commit ID>
當Git沒法自動合併分支時,就必須首先解決衝突。解決衝突後,再提交,合併完成。spa
解決衝突就是把Git合併失敗的文件手動編輯爲咱們但願的內容,再提交。指針
.gitignore
這個文件的做用,會去忽略一些不須要歸入Git管理這種,咱們也不但願出如今未跟蹤文件列表。code
# 此行爲註釋 會被Git忽略 # 忽略 node_modules/ 目錄下全部的文件 node_modules # 忽略全部.vscode結尾的文件 .vscode # 忽略全部.md結尾的文件 *.md # 但README.md 除外 !README.md # 會忽略 doc/something.txt 但不會忽略doc/images/arch.txt doc/*.txt # 忽略 doc/ 目錄下全部擴展名爲txt文件 doc/**/*.txt
git merge <要合併的分支>對象
git add
、git commit
參考圖片