git 學習筆記#
使用技巧#
Github 專案內搜尋#
在倉庫頁面上按 T ,然後直接輸入檔案名稱
記錄#
Gitee 配置的記錄#
因為 srtp 專案是用 gitee 作托管,所以今天試著配置了下 Gitee,還是花了些時間的,記錄如下:
- 主要參考的是Git 同時配置 Gitee 和 GitHub,但它上面第一步就是讓清除 git 的全局設置,有點不敢,因為怕清除後自己之前設置的一些東西出錯。
- 又看了幾個教程,發現Github 與 Gitee 共存配置上並沒有說要清楚全局設置,於是就跟著上面的一步步走,很順利地就設置好了。
- 一個收穫是
config,id_rsa都是可以用記事本打開並編輯的。
多人協作時的流程#
這次小組專案用的是華為雲,所以流程也都是基於華為雲來說的。
對 remote branch 的認識#
There are potentially three versions of every remote branch:
- The actual branch on the remote repository
- The snapshot of that branch locally
- A local branch that might be tracking the remote branch
常用命令#
add#
git add .會根據。gitignore 做過濾git add *會忽略。gitignore 把任何檔案都加入
推送#
檔案推送的三個步驟:
查看狀況#
git status
分支#
-
轉到另一個分支
git checkout {分支名稱} -
查看本地分支
git branch -
查看遠端分支
git branch -r -
查看本地和遠端分支
git branch -a -
刪除本地分支
git branch -d {本地分支名稱} -
強制刪除本地分支
git branch -D {本地分支名稱} -
刪除遠端分支
git push origin --delete {遠端分支名稱} -
已經刪除的遠端分支但仍
git branch -a時仍顯示 :git remote prune origin
日誌#
git log查看分支提交歷史git reflog也是查看日誌,主要區別是會顯示reset --hard
程式碼回退#
git reset --hard {commit_id}git reset --hard HEAD^回退到上一版本
錯誤與解決#
-
錯誤:
Updates were rejected because the remote contains work that you donot have locally.
- 場景: 在嘗試 gitee 的時候,先是建了個遠端倉庫。然後在本地新建了個同名的資料夾,然後
在資料夾裡新建了個檔案,
push的時候報的錯- 解決: 根據下方的提示,是我沒有先
pull,本地檔案不是最新的。
-
Updates were rejected because the tip of your current branch is behind its remote counterpart
- 場景:上述那個場景中,
git pull origin master後報的錯 - 解決:
git pull origin master --rebase - 參考連結:Git 常見報錯:Updates were rejected because the tip of your current branch is behind
- 收穫:雖然使用 GitHub 托管程式碼有段時間了,但一直是用插件簡化操作的。這次算是第一次用 git bash,就報了兩個錯,感覺 git 要用好,還是有段路要走的。
- 場景:上述那個場景中,
-
- 場景時報錯,大意是網路問題
- 解決: