git 操作常見錯誤及解決方式---(實戰性總結)

1.GitBash 配置到WebStorm中

File–>settings–>Tools–>Terminal
更改Shell Path中cmd.exe爲sh.exe的路徑

注意:這裏的路徑是sh.exe的路徑不是gitbash.exe的路徑

"C:\Program Files\Git\bin\sh.exe" --login -i

在這裏插入圖片描述

2.解決git pull/git push 每次都要輸入用戶名密碼的問題

出現這個問題的原因是git clone下載代碼時候的鏈接是https://而不是git@git(ssh)的形式,當我們操作git pull/push到遠程的時候,總是提示我們輸入賬號和密碼才能操作成功。
解決方法:在項目目錄下執行

git config --global credential.helper store

這個操作會在你本地生成一個文本,上邊記錄你的賬號和密碼然後你使用上述的命令配置好之後,再操作一次git pull,然後它會提示你輸入賬號密碼,這一次之後就不需要再次輸入密碼了。

3.Git操作fatal: Authentication failed for 'http://********

身份驗證失敗,且不彈出用戶名密碼問題解決:執行以下命令清除用戶名密碼緩存

git config --system --unset credential.helper

4.error: could not lock config file C:/Program Files/Git/mingw64/etc/gitconfig: Permission denied

出現Permission denied這種情況應該在管理員權限下運行
打開PowerShell 運行

git config --system --unset credential.helper

5.RPC failed; HTTP 411 curl 22 The requested URL returned error: 411 Pushing to “http://……”

錯誤原因:git 通過http post的大小有限制
解決方式git config http.postBuffer 524288000 設置上傳的最大數據量爲50MB

6.fatal: not a git repository (or any of the parent directories): .git

錯誤原因:git clone遠程項目到本地後執行其它git命令如git add .,提示當前的操作目錄中沒有.git文件,也就是說當前並不一個Git上的遠程倉庫目錄,所以Git命令設置無效。
解決辦法:輸入git init命令,它可以創建一個全新的空倉庫,或者將已經存在的項目納入版本管理。

7.There is no tracking information for the current branch.Please specify which branch you want to merge with.

錯誤原因:在執行git pull命令的時候提示當前分支沒有跟蹤信息
解決方法
 1.直接指定遠程分支
 git pull remote branch如git pull origin master
 2.另外一種方法就是先指定本地master到遠程的master,然再去pullgit branch --set-upstream-to=remote/branch master如git branch --set-upstream-to=origin/master master

fatal: ‘origin’ does not appear to be a git repository

fatal: Could not read from remote repository.
錯誤原因:當運行 git clone ~~來克隆存儲庫時,將自動創建默認的遠程起點。 如果存儲庫是由 git init 創建的,那麼就沒有remote,也沒有 origin,需要自己設置。
解決方法:執行git remote add origin <repo_url>
Repo url 是要與其交換數據的現有遠程存儲庫的路徑。 如果它位於本地磁盤,它可以是 file: / / home / me / foo。 Git or / home / me / foo. 飯桶。 如果它是在 Github 上託管的,那麼它可以是 https://Github.com/me/foo.git 或者 ssh: / / git@ Github.com/me/foo.git。
參考答案

8.fatal: branch ‘master’ does not exist

錯誤原因:
1.本地創建一個本地倉庫
2.關聯遠程端:
 git remote add origin [email protected]:用戶名/遠程庫名.git
3.同步遠程倉庫到本地
 git pull這個時候會報錯If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master
 再按提示執行
git branch --set-upstream-to=origin/master master
 繼續報錯
fatal: branch 'master' does not exist
原因:本地倉沒有在master上所以報錯了
解決方法:
 在本地倉切換到master,git checkout master那麼剛剛同步的文件就出來了這裏實際遠程端的其他分支也同步了下來的了,但是git branch 不會展示出來直接 git checkout 分支名 就可以直接切過去了這裏如果 使用 git clone [email protected]:用戶名/ --克隆遠程倉 那麼master 和分支都會展示出來。實際: 試了也是一樣的 git branch 也是看不到 分支,但是實際也是下載下來了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章