首先明確使用git的用處,它作為版本控制工具,上傳/更新項目到github。
其次明確git的工作原理。
先將項目放在工作區(即本地倉庫),然后通過add操作放到版本庫的暫存區(這個過程使得本地倉庫要上傳的文件被跟蹤),再通過commit操作放到版本庫的當前分支。接下來將本地倉庫和github的遠程服務器倉庫關聯起來,再執行push操作。這里關聯有兩種方式,一是通過ssh密鑰方式,一是通過remote操作關聯url地址。
但是,在具體操作中會出現一些大大小小的問題和錯誤,一下記錄遇到的坑和可能有效的解決方式。
1、進行push操作的時候,提示
fatal: refusing to merge unrelated histories
或者
error: failed to push some refs to 'https://github.com/***********’ hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
造成以上錯誤的原因有可能是這樣的:
上圖是我們在github上創建倉庫的頁面,勾選了創建README的選項。那么生成的遠端庫就會有一個README.md文件,這個文件跟我們本地庫沒有關系(要知道我們從本地庫上傳到遠端庫的文件都是經過add操作,即被跟蹤了的)
這就造成了我們push還是pull的時候,遠端庫覺得本地庫跟自己沒關系,導致操作失敗。
比較簡單的解決方法有2種:
1)在創建倉庫的時候不要勾選那個選項
2)在進行pull操作前,在git-bash終端輸入
git pull origin master --allow-unrelated-histories //把兩段不相干的分支進行強行合並
2、進行commit操作的時候,提示
On branch master
nothing to commit, working tree clean
應該有挺多可能的原因,我遇到這個問題是因為上面那個坑。解決上面那個坑后,在add后直接push就成功了。
3、上傳vs項目,進行add操作的時候,提示
error: open(".vs/ExperimentImg/v16/Browse.VC.opendb"): Permission denied error: unable to index file '.vs/ExperimentImg/v16/Browse.VC.opendb' fatal: adding files failed
借鑒:https://www.cnblogs.com/Fred1987/p/10934705.html
4、進行remote操作時,提示
fatal: remote origin already exists.
輸入:git remote rm origin
重新進行remote操作
5、進行push操作時,提示
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git
原因是我們上傳的項目太大了,超過了100m
參考
------------恢復內容結束------------