git相关问题集锦

简易的命令行入门教程:

centos安装高版本git
通过git –version查看系统带的版本,Cento6.5应该自带的是git版本是1.7.1

># yum remove git
下载git2.2.1并将git添加到环境变量中
># wget https://github.com/git/git/archive/v2.2.1.tar.gz
># tar zxvf v2.2.1.tar.gz
># cd git-2.2.1
># make configure
># ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
># make all doc
># make install install-doc install-html
># echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
># source /etc/bashrc
查看版本号
># git --version
>git version 2.2.1

Git 全局设置:

创建 git 仓库:

已有项目?

fatal: remote origin already exists.

,则先运行

git remote rm origin

,再运行

git remote add origin https://git.oschina.net/rowger_217/ceshi.git
  • git push -u origin master

服务器项目强制覆盖本地(此时本地改动会被覆盖掉)

git fetch --all  
git reset --hard origin/master 
git pull

远程项目合并到本地

  • git pull origin master

问题集锦

在服务端git pull之后报错

error: Your local changes to the following files would be overwritten by merge:

解决办法:

如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

git stash
git pull
git stash pop

然后可以使用Git diff -w +文件名 来确认代码自动合并的情况.

反过来,如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:

git reset --hard
git pull

LF will be replaced by CRLF in

解决办法:

git config --global core.autocrlf false

Windows上设置避免每次git push 都需要账号密码

在 C:\Users\luojie\ 目录下 能看到 [.gitconfig] 这个文件:

[user]  
    name = kn****  
    email = ************.com  
[credential]  
    helper = store

配置了credential之后就可以存储账号密码,下次不用再输入

linux上设置避免每次git push 都需要账号密码

  • 先cd到根目录,执行git config --global credential.helper store命令
[root@iZ25mi9h7ayZ ~]# git config --global credential.helper store
  • 执行之后会在.gitconfig文件中多加红色字体项
[user]
        name = luojie
        email = xxxx@xxxx.com
[credential]
        helper = store
  • 之后cd到项目目录,执行git pull命令,会提示输入账号密码。输完这一次以后就不再需要,并且会在根目录生成一个.git-credentials文件

报错fatal: Unable to find remote helper for 'https'

当你编译安装git时因为没有安装(lib)curl-devel所以导致git clone 和 git push 都会出现这个错误
如果你安装了(lib)curl-devel,然后重新编译安装git就没有这个错误了:

$ yum install curl-devel
$ # cd to wherever the source for git is
$ cd /usr/local/src/git-1.7.9 
$ ./configure
$ make
$ make install

报错 SSL certificate problem: self signed certificate

报错 SSL certificate problem: certificate has expired

解决办法:永远不验证ssl证书

git config --global http.sslVerify false
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容