Git开发中常见的错误以及处理

Git常见的错误以及处理

1.添加远程仓库ios

 $ git remote add origin (github账号名)/gitdemo(项目名).git 
复制代码

解决办法以下:git

一、先输入git remote rm origin   
二、再输入 git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!
三、若是输入$ git remote rm origin 仍是报错的话,error: Could not remove config section 'remote.origin'. 咱们须要修改gitconfig文件的内容
四、找到你的github的安装路径,个人是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
五、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就行了!github

2.提交代码时提示错误shell

requested URL returned error: 403 
//若是出现403 表示没有权限提交代码
复制代码

2.1.解决办法以下:vim

在.git配置文件下加上username:password@就行了 (SmartTuwei:Tw10432845..@github.com/SmartTuwei/…)缓存

2.2.也能够清除掉git客户端中的缓存信息bash

$ git credential-manager uninstall  
$ git credential-manager install  
复制代码

3.若是输入$ ssh -T git@github.com, 提示错误服务器

Permission denied (publickey).
//由于新生成的key不能加入ssh就会致使链接不上github。
复制代码

解决办法以下:
一、先输入app

$ ssh-agent,再输入$ ssh-add ~/.ssh/id_key ,
复制代码

这样就能够了。
二、若是仍是不行的话,输入ssh-add ~/.ssh/id_key 命令后出现报错Could not open a connection to your authentication agent.解决方法是key用Git Gui的ssh工具生成,这样生成的时候key就直接保存在ssh中了,不须要再ssh-add命令加入了,其它的user,token等配置都用命令行来作。
三、最好检查一下在你复制id_rsa.pub文件的内容时有没有产生多余的空格或空行,有些编辑器会帮你添加这些的。ssh

4.若是输入$ git push origin master,提示出错信息:

error:failed to push som refs to .......
复制代码

解决办法以下:

一、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来
二、再输入$ git push origin master
复制代码

若是继续报错:

fatal: Couldn't find remote ref master或者
fatal: 'origin' does not appear to be a git repository以及
fatal: Could not read from remote repository.
复制代码

则须要从新输入

$ git remote addorigingit@github.com:djqiang/gitdemo.git
复制代码

5.输入$ git push -u origin master To git@github.com:******/Demo.git

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
复制代码

是由于远程repository和我本地的repository冲突致使的,而我在建立版本库后,在github的版本库页面点击了建立README.md文件的按钮建立了说明文档,可是却没有pull到本地。这样就产生了版本冲突的问题。

有以下几种解决方法:
1.使用强制push的方法:

$ git push -u origin master -f
复制代码

这样会使远程修改丢失,通常是不可取的,尤为是多人协做开发的时候。
2.push前先将远程repository修改pull下来

$ git pull origin master  
$ git push -u origin master  
复制代码

3.若不想merge远程和本地修改,能够先建立新的分支:

$ git branch [name]  而后push  $ git push -u origin [name]; 
复制代码

6.gitconfig配置文件

Git有一个工具被称为gitconfig,它容许你得到和设置配置变量;这些变量能够控制Git的外观和操做的各个方面。这些变量能够被存储在三个不一样的位置:
1./etc/gitconfig 文件:包含了适用于系统全部用户和全部库的值。若是你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。
2.~/.gitconfig 文件 :具体到你的用户。你能够经过传递--global 选项使Git 读或写这个特定的文件。
3.位于git目录的config文件 (也就是 .git/config) :不管你当前在用的库是什么,特定指向该单一的库。每一个级别重写前一个值。所以,在.git/config中的值覆盖了在/etc/gitconfig中的同一个

7.配置相关信息:

7.1.当你安装Git后首先要作的事情是设置你的用户名称和e-mail地址。这是很是重要的,由于每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
复制代码

7.2.你的编辑器(Your Editor)

如今,你的标识已经设置,你能够配置你的缺省文本编辑器,Git在须要你输入一些消息时会使用该文本编辑器。缺省状况下,Git使用你的系统的缺省编辑器,这一般多是vi 或者vim。若是你想使用一个不一样的文本编辑器,例如Emacs,你能够作以下操做:

$ git config --global core.editor emacs  
复制代码

7.3 若是你想检查你的设置,你可使用

git config --list 命令来列出Git能够在该处找到的全部的设置:       
$ git config --list
git config user.name   
复制代码

8.github版本库,在push代码时出错:

8.1提交时报错( You have not concluded your merge (MERGE_HEAD exists))

处理办法:强制push : $ git push -u [远程分支] -f

相关文章
相关标签/搜索