错误信息

error: The requested URL returned error: 401 Unauthorized while accessing https://git.oschina.net/zemo/demo.git/info/refs
fatal: HTTP request failed

解决方案

1、安装依赖
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc
[root@localhost ~]# yum install  gcc perl-ExtUtils-MakeMaker
2、卸载系统自带的底版本git(1.7.1)
[root@localhost ~]# git --version
git version 1.7.1
[root@localhost ~]# yum remove git

3、编译安装最新的git版本
[root@localhost ~]# cd /soft/      进入下载文件的目录
[root@localhost soft]# wget https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.xz
[root@localhost soft]# tar -vxf git-2.15.1.tar.xz
[root@localhost soft]# cd git-2.15.1
[root@localhost git-2.15.1]# make prefix=/git all    编译  prefix指定目录
[root@localhost git-2.15.1]# make prefix=/git install    安装  prefix指定目录
[root@localhost git-2.15.1]# echo "export PATH=$PATH:/git/bin" >> /etc/profile    设置环境变量
[root@localhost git-2.15.1]# source /etc/profile    保证环境变量立即生效
4、如果上面下载执行报错,请使用最下面一行的语句
[root@localhost soft]# wget https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.xz
--2001-02-27 11:29:07--  https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.xz
Resolving www.kernel.org... 147.75.46.191, 2604:1380:4080:c00::1
Connecting to www.kernel.org|147.75.46.191|:443... connected.
ERROR: cannot verify www.kernel.org’s certificate, issued by “/C=FR/ST=Paris/L=Paris/O=Gandi/CN=Gandi Standard SSL CA 2”:
  Issued certificate not yet valid.
To connect to www.kernel.org insecurely, use ‘--no-check-certificate’.
[root@localhost soft]# wget https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.xz --no-check-certificate
5、查看最新的git版本
[root@localhost ~]# git --version
git version 2.15.1
6、遇此问题的解决方法:修改系统时间就OK
Warning: File `../table/table.pro' has modification time 3.9e+08 s in the future
7、第二天打开服务器输入git仍然提示:-bash: git: command not found,解决方法:设置环境变量即可解决
echo "export PATH=$PATH:/git/bin" > /etc/profile.d/git.sh
source /etc/profile.d/git.sh
git --version
8、git相关指令
git为本地分支设置对应的远程分支
当运行git pull时,如果本地分支没有绑定远程分支,将无法正常pull。
运行如下命令即可关联本地和远程分支:
git branch --set-upstream-to=origiin/branchName
9、检出新分支
  • git checkout -b new-branch
  • 提交上面检出的新分支:git push origin HEAD:远程新branchName
10、添加忽略文件并生效
  • 在.gitignore文件中添加要忽略的文件,添加好后执行下述命令:
  • git rm -r --cached . // 删除本地缓存
  • git add . // 添加要提交的文件
  • git commit -m ‘update .gitignore’ // 更新本地的缓存
11、已经commit 但没有push的内容撤销
  • git reset --soft HEAD^
12、状态查看&提交代码&合并分支代码命令
  • git status 查看工作区代码相对于暂存区的差别
  • git add . 将当前目录下修改的所有代码从工作区添加到暂存区 . 代表当前目录
  • git commit -m ‘注释’ 将缓存区内容添加到本地仓库
  • git push origin master 将本地版本库推送到远程服务器,
  • git merge 分支名 合并分支
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐