[长期更新][Git] 问题汇总 & 分析解决

【说明】:目前正在学习 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
# @ 参考
...
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由系统于 7年前 自动加精
讨论数量: 12
wanghan

这个厉害了!

7年前 评论

@wanghan 别呀 我是菜菜鸟

7年前 评论
幽弥狂

还不错的样子。。。

7年前 评论
幽弥狂

@徐俊 :+1:

7年前 评论
Aaron
楼主排版很好看
7年前 评论

降龙十八赞~

7年前 评论

:+1: ,很好,先mark

7年前 评论

git 中heroku login 登录不上,总是报错:

file

file
这两种错误。怎么能解决呢?

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!