# Git安装与问题
# Flag
- https://github.com/git (opens new window)
- https://www.syntevo.com (opens new window)
- https://github.com/github/gitignore (opens new window)
- https://github.com/toptal/gitignore.io (opens new window)
- reposurgeon是一种工具,用于编辑版本控制存储库的历史 (opens new window)
- https://github.com/gitextensions/gitextensions (opens new window)
- GUI https://github.com/git-cola/git-cola (opens new window)
- https://github.com/TortoiseGit (opens new window)
SVN
按装
VisualSVN
后客户端使用报错:执行上下文错误: 由于目标计算机积极拒绝,无法连接。
,需要在服务
列表中找到相关服务 -> 右键打开属性 -> 点击登录页签修改登录身份
为本地系统账户
-> 点击常规页签修改启动类型
为自启动
,再点击启动
- Edge:RESTful API https://www.collab.net/downloads/subversion (opens new window)
- https://www.wandisco.com/source-code-management/subversion (opens new window)
- https://sliksvn.com/pub (opens new window)
- https://github.com/jenkinsci/subversion-plugin (opens new window)
- https://github.com/subclipse (opens new window)
Git与SVN区别
- git是分布式,svn是集中式;
- svn只有一个中央版本库,而git有无限个;
- svn有全局的版本号,git没有;
- git不必联网就可以看到所有的log,svn必须联网;
- git保存的是元数据,svn是复制整个文档;
- git强调分支,svn只是不同的文件目录,就是copy
# 安装最新版
- https://git-scm.com/download (opens new window)
- https://npm.taobao.org/mirrors/git-for-windows (opens new window)
- https://packages.endpoint.com/rhel/7/os/x86_64/git-2.24.1-1.ep7.x86_64.rpm (opens new window)
- https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm (opens new window)
- 方式一
yum install -y http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
# 或者
wget http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
rpm -ivh wandisco-git-release-7-2.noarch.rpm
curl https://setup.ius.io | sh
# 或者
yum install -y epel-release
rpm -ivh https://centos7.iuscommunity.org/ius-release.rpm
# 查看git包版本
yum list git2u
# 安装
yum -y install git2u
# 常见问题处理
# 项目过大clone报错
- 由于提交了比较大的文件,在服务端一直无法拉下来,错误如下
Cloning into 'E:\soft'...
POST git-upload-pack (175 bytes)
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
fatal: early EOF
fatal: the remote end hung up unexpectedly
fatal: index-pack failed
- 执行命令
# 修改压缩的程度
git config --global core.compression 0
# 解决内存不够问题
git config --global pack.deltaCacheSize 2047m
git config --global pack.packSizeLimit 2047m
git config --global pack.windowMemory 2047m
git config --global core.packedGitWindowSize 512m
git config --global core.packedGitLimit 512m
# 调整缓存大小(单位为字节)为1G
git config --global http.postBuffer 1073741824
# 最低速度限制
git config --global http.lowSpeedLimit 0
# 最低速度时间
git config --global http.lowSpeedTime 999999
compression 是压缩的意思,从 clone 的终端输出就知道,服务器会压缩目标文件,然后传输到客户端,客户端再解压。 取值为 [-1, 9],-1 以 zlib 为默认压缩库,0 表示不进行压缩,1..9 是压缩速度与最终获得文件大小的不同程度的权衡, 数字越大,压缩越慢,当然得到的文件会越小。
# 提交本地文件失败
在github远程创建仓库后, 利用gitbash进行提交本地文件的时候出现如下错误
[root@foundation38 demo]# git push -u origin master
Username for 'https://github.com': woytu
Password for 'https://woytu@github.com':
To https://github.com/woytu/test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/woytu/test.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.
- 第一种:进行push前先将远程仓库pull到本地仓库
# git pull --rebase origin master
git pull origin master
git push -u origin master
- 第二种:强制push本地仓库到远程
git push -u origin master -f
- 第三种:避开解决冲突, 将本地文件暂时提交到远程新建的分支中
git branch [name]
# 创建完branch后, 再进行push
git push -u origin [name]
# 远端与本地代码冲突
- 先将本地修改存储起来
# 暂存修改,这样本地的所有修改就都被暂时存储起来
git stash
# 看到保存的信息,其中stash@{0}就是刚才保存的标记。
git stash list
暂存了本地修改之后,pull内容
还原暂存的内容
git stash popstash@{0}
- 系统提示如下类似的信息
Auto-mergingc/environ.c
CONFLICT(content): Merge conflict in c/environ.c
意思就是系统自动合并修改的内容,但是其中有冲突,需要解决其中的冲突。
- 解决文件中冲突的的部分
打开冲突的文件,其中
Updatedupstream
和=====
之间的内容就是pull下来的内容,====
和stashed changes
之间的 内容就是本地修改的内容。碰到这种情况,git也不知道哪行内容是需要的,所以要自行确定需要的内容。
# SSL验证错误
报错
unable to access 'https://github.com/': OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
- 关闭SSL验证
env GIT_SSL_NO_VERIFY=true
# 或者
git config --global http.sslVerify false
- 去掉代理
git config --global --unset http.proxy
# push错误
The following untracked working tree files would be overwritten by merge/checkout
git clean -d -fx
-n
显示将要删除的文件和目录;-x
删除忽略文件已经对git来说不识别的文件-d
删除未被添加到git的路径中的文件-f
强制运行
fatal: refusing to merge unrelated histories
git pull origin master --allow-unrelated-histories
可以允许不相关历史提,强制合并