Git使用指南

2021-07-09 by uino 64 研发

Git账号开通

如果已经开通了公司的腾讯企业邮箱,企业微信账号并已登录,确认企业微信个人信息的邮箱地址与手机号录入信息无误后可以登录以下地址开通

Git仓库地址

https://git.uino.com

Git客户端下载

  • Mac 用户自带,假如没有可以执行brew install git
  • CentOS/Redhat 安装命令yum install git -y
  • Debian/Ubuntu 安装命令apt install git -y
  • Windows git Win 用户可以下载它,安装后 VSCode 会自动识别的

2FA二次验证重置

为了Git仓库代码的安全性,网站强制所有账号开通二次验证,如果您的设备丢失没办法登陆站点可以通过以下方式进行在线重置

如果以上操作失败可以邮件或者企业微信联系李忠(lizhong@uino.com)进行人工处理

离职人员如何关闭Git账号

如果您的小组内有小伙伴离职,Git平台会在24-48小时内自行关闭离职人员账号,如果您不放心,可以在48小时后到这个地址查询

如果查询结果显示已离职的小伙伴账号未关闭,可以邮件或者企业微信联系李忠(lizhong@uino.com)进行人工处理

gitignore规范

所有的项目根目录下,必须创建.gitignore文件,把不需要的提交到 Git 的文件都忽略

原则上,只要使用包管理能从第三方包下载的包,以及 IDE 产生的文件都不要提交的 GIT,下面是一个常用的配置,大家自行删减

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db

WARNING: POSSIBLE DNS SPOOFING DETECTED 错误解决

在git执行任何操作时会出现类似以下错误,表示DNS或者主机唯一身份发生改变

$ ssh -T git@git.uinnova.com  
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for git.uinnova.com has changed,
and the key for the corresponding IP address 101.201.211.135
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:DpGRe1sO6MD050GK+bIWsH1BzaXAa0szonYtyxvhkzw.
Please contact your system administrator.
Add correct host key in /Users/nicholas/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/nicholas/.ssh/known_hosts:15
ECDSA host key for git.uinnova.com has changed and you have requested strict checking.
Host key verification failed.

此时,我们按照下面的命令刷一下,Windows用户请在git bash下执行

$ ssh-keygen -f ~/.ssh/known_hosts -R git.uinnova.com
# Host git.uinnova.com found: line 15
/Users/nicholas/.ssh/known_hosts updated.
Original contents retained as /Users/nicholas/.ssh/known_hosts.old

然后,我们随意执行git push pull clone任意操作即可,中间会提示你

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

yes,然后回车即可,以上询问仅提问一次,不必担心每次都会提问,除非发生了相关变更。

$ ssh -T git@git.uinnova.com
The authenticity of host 'git.uinnova.com (101.201.211.135)' can't be established.
ECDSA key fingerprint is SHA256:DpGRe1sO6MD050GK+bIWsH1BzaXAa0szonYtyxvhkzw.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'git.uinnova.com,101.201.211.135' (ECDSA) to the list of known hosts.
Welcome to GitLab, @lizhong!

SSH Key 生成

Git 采用 SSH 协议认证,必须生成 SSHKey 才能获取或者推送代码