git安装配置和连接码云公钥

来源:互联网 发布:网络聚集系数 编辑:程序博客网 时间:2024/05/17 09:37

Git简介

Git是一个免费开源的分布式版本控制系统
可以有效的高速的处理从很小到非常大的项目版本管理

GIT安装

git(linux安装)
下载地址 源码包 https://github.com/git/git/archive/v2.15.0.tar.gz
依赖安装

sudo yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

安装
tar -zxvf v2.15.0.tar.gz
对下载的源码包进行编译
cd git-v2.15.0
make perfix=/usr/local all
sudo make perfix=/usr/loacl install

Window请直接下载安装 一键式安装下载地址 https://git-scm.com/download/win

配置

配置用户名(提交时候会引用)

git config --global user.name "yourusername"   『--global表示是全局的』

配置邮箱

git config --golbal user.email "youremail"

冲突merge使用版本 git config --global merge.tool "kdiff3" (没装kdiff3忽略本行)

让Git不要管Windows/Unix换行符转换的事

git config --global core.autocrlf false

编码配置

避免git gui中的中文乱码

git config --global gui.encoding utf-8

避免git status显示的中文名乱码

git config --global core.quotepath off

windows区分大小写设置

 git config --global core.ignorecase false

git ssh key pair配置 码云配置

1.在linux的命令行下,或者是windows上Git Bash命令行窗口中键入:

ssh-keygen -t rsa -C "xxxx@xx.com"

2.一直按回车(Enter),不要输入任何密码之类,生成 ssh key pair
3. ssh-add ~/.ssh/id_rsa
如果出现 Could not open a connection to your authentiacation agent 执行 eval `ssh-agent` (`反引号)
在执行ssh-add ~/.ssh/rsa成功ssh-add l就有新加的rsa了
4.cat ~/.ssh/id_rsa.pub (查看)
5.将公钥复制出来
6.gitlib右上角个人资料,进入SSH公钥配置 复制的东西加进去提交
这里写图片描述
这里写图片描述

git提交时忽略文件配置

在项目根目录创建 .gitingore文件

忽略所有的class

*.class

包文件 package file *.jar(如果使用中央仓库中没有的jar的话不能添加这句)

*.war
*.ear

使用了kdff3的话 kdiff3 ignore

*.orig

maven编译忽略

target/

eclipse ignore

.settings.project.classpath

idea 忽略

.idea//idea/*.ipr*.iml*.iws

临时文件

*.log*.cache*.patch*.tmp

系统临时文件(MAC)

.DS_StoreThumbs.db

使用命令: git status 查看状态
git init 初始化仓库
git add . 将所有文件(除去忽略的文件,添加到仓库中)
git commit -am “添加注释” 提交文件到仓库

推送到远程仓库

1.复制远程仓库地址 git@gitee.com:xxxxx/xxxx.git 添加远程仓库

 git remote add origin git@gitee.com:xxxxx/xxxx.git

2.查看分支

git branchgit push -u[-f] origin master  (-f表示强制更新)执行 git push -u origin master 报错 【注意yes/no时候不能直接回车要输入 yes 否则会出现 Host key verification failed.】D:\work\xxxx>git push -u origin masterThe authenticity of host 'gitee.com (218.11.0.86)' can't be established.ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'gitee.com,218.11.0.86' (ECDSA) to the list of known hosts.To gitee.com:xxxxx/xxxx.git ! [rejected]        master -> master (fetch first)error: failed to push some refs to 'git@gitee.com:xxxxx/xxxx.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.解决办法:1.先执行下  git pull 【拉取一下】2.执行 git push -u origin master如果还报错的话 git push -u -f origin master 【强制替换更新】

————–主流的开发模式支线开发 主干发布————–
查看本地分支 git branch
查看远程分支 git branch -r
— 创建分支
git checkout -b v1.0 origin/master 【 -b表示创建新的分支 origin/master 表示v1.0在远程 master的基础上 】
发部到远程仓库
git push origin HEAD -u 远程会有两个仓库 master v1.0

分支切换 git checkout [master/v1.0] 切换分支