【長期更新】【Git】問題彙總 & 分析解決

徐俊發表於2017-06-09

【說明】:目前正在學習 Git,由於本人比較遲鈍所以打算將使用 Git 過程中自己所遇到的問題都整理記錄下來,希望能夠幫助到和我遇到相同問題的朋友

【感謝】:感謝本文中所有連結的作者提出個各種解決方案與分析,分享的精神是值得尊重的

# @ 問題
$ git add -A 納入版本控制時提示警告 "warning:CRLF will be replaced by LF in ..."
# @ 分析
Git 預設會進行換行檢查,此警告只是檢測到 Windows 的換行並提示會將其替換
# @ 解決
$ git config --global core.autocrlf false
# @ 參考
http://blog.csdn.net/feng88724/article/details/11600375
# @ 問題
$ git remote add origin 提示錯誤 "fatal: remote origin already exists"
# @ 分析
可能是由於系統已經配置過遠端倉庫?(清楚瞭解的朋友歡迎糾正)
# @ 解決
$ git remote rm origin
# @ 參考
http://blog.csdn.net/dengjianqiang2011/article/details/9260435
# @ 問題
$ git push -u origin master 提示錯誤:
...
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
...
# @ 分析
據瞭解是由於遠端的 Master 版本和本地的不同所導致
# @ 解決
$ git pull origin master
# @ 參考
http://www.oschina.net/question/780536_121856
# @ 問題
$ git push heroku master 上傳專案至 Heroku 出現錯誤 :
...
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
...
# @ 分析
由於沒有新增 Heroku 遠端倉庫所導致
# @ 解決
$ git remote -v 檢視當前所有遠端倉庫,若沒有 Heroku 的倉庫則通過下列命令新增
$ git remote add <自定義倉庫名> <倉庫地址> ( 例如:git remote add Maldini https://git.heroku.com/mighty-harbor-34894.git )
# @ 參考
...
# @ 問題
$ git push heroku master 上傳專案至 Heroku 出現錯誤
...
Counting objects: 38, done.
Compressing objects: 100% (34/34), done.
Writing objects: 100% (38/38), 4.42 KiB | 0 bytes/s, done.
Total 38 (delta 31), reused 2 (delta 2)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote:
remote:  !     ERROR: Could not parse 'composer.lock'; make sure it's valid!
remote:
remote:  !     Push rejected, failed to compile PHP app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to desolate-stream-71234.
remote:
To https://git.heroku.com/desolate-stream-71234.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/desolate-stream-71234.git'
...
# @ 分析
這個問題是由一系列問題所導致的:
由於之前本人上傳專案至 Git 的時候起了衝突以至於衝突的檔案都被加一些標記例如 <<<<<<HEAD 之類的
這樣就導致連環報錯,找了許多資料才發現這個線索
# @ 解決
程式碼上傳時無論如何執行下,看下有沒有報錯
# @ 參考
...
# @ 問題
$ git pull origin master 從遠端倉庫更新至本地時出現錯誤:
...
error: Pull is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
...
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.
...
# @ 分析
大致的原因可能是本地的倉庫和遠端倉庫的某些東西不一致,可能是沒合併或者有修改之類...
# @ 解決
$ git fetch <遠端倉庫名> <分支> 先下載遠端的版本( 例如:git fetch origin master )
$ git reset --hard <倉庫名>/<分支> ( 例如:git reset --hard origin/master )
# @ 參考
http://www.cnblogs.com/shuiyelifang/p/6518533.html
http://blog.csdn.net/commonslok/article/details/50721320
# @ 問題
$ git pull 失敗出現錯誤:
...
Your branch is up-to-date with 'origin/Test_Branch'.
Already on 'Test_Branch'
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
...
# @ 分析
由於今天更改了專案地址,所以導致舊的專案地址無法使用,其實類似的問題大多是因為許可權/倉庫地址/倉庫屬性(如:私有倉庫沒把當前使用者加進去之類的小錯誤)
# @ 解決
$ git remote remove <舊倉庫地址>
$ git remote add <自定義倉庫名> <新倉庫地址>
# @ 參考
...
# @ 問題
$ composer Git Bash 使用 PHP Composer 出現錯誤:
bash: composer: command not found
# @ 分析
Composer 沒有加入環境變數或者環境變數中缺少相應的檔案
# @ 解決
確保你已經配置了環境變數並且包含了以下三個檔案:
 - compoer
 - compoer.bat
 - composer.phar
# @ 參考
...

相關文章