# Git服务
# Flag
- 忽略提交 https://github.com/github/gitignore (opens new window)
- https://github.com/toptal/gitignore.io (opens new window)
- 编辑版本控制存储库的历史 http://www.catb.org/esr/reposurgeon (opens new window)
- GUI https://github.com/git-cola/git-cola (opens new window)
- https://github.com/gitextensions/gitextensions (opens new window)
- https://github.com/TortoiseGit (opens new window)
- https://www.syntevo.com (opens new window)
- https://www.git-tower.com (opens new window)
- 代码语法突出 https://github.com/sharkdp/bat (opens new window)
- Git核心方法的可移植的纯C实现 https://github.com/libgit2/libgit2 (opens new window)
- 来自配置错误的网站的Git仓库泄漏 https://github.com/liamg/gitjacker (opens new window)
- git加密 https://github.com/AGWA/git-crypt (opens new window)
- 自动补全 https://github.com/dahlbyk/posh-git (opens new window)
- https://github.com/JanDeDobbeleer/oh-my-posh (opens new window)
- 依赖项更新 https://github.com/renovatebot/renovate (opens new window)
- Git工具 https://github.com/GitTools (opens new window)
- https://github.com/sosedoff/gitkit (opens new window)
- SmartGit 是一款优秀的图形化Git仓库管理工具
- SmartSVN 是一款优秀的图形化SVN仓库管理工具
- 根据日志生成Changelog https://github.com/orhun/git-cliff (opens new window)
- Java实现 https://github.com/eclipse/jgit (opens new window)
- https://github.com/gitblit/gitblit (opens new window)
- https://github.com/scm-manager/scm-manager (opens new window)
- https://github.com/projectkudu/kudu (opens new window)
Git与SVN区别
- git是分布式,svn是集中式;
- svn只有一个中央版本库,而git有无限个;
- svn有全局的版本号,git没有;
- git不必联网就可以看到所有的log,svn必须联网;
- git保存的是元数据,svn是复制整个文档;
- git强调分支,svn只是不同的文件目录,就是copy
其他版本控制系统软件
- https://www.perforce.com (opens new window)
- https://www.mercurial-scm.org (opens new window)
- https://www.nongnu.org/cvs (opens new window)
- https://bazaar.canonical.com (opens new window)
- https://github.com/bytebase/bytebase (opens new window)
- https://nest.pijul.com/pijul/pijul (opens new window)
其他版本控制服务
- https://code.aliyun.com (opens new window)
- https://coding.net (opens new window)
- https://git.code.tencent.com (opens new window)
- https://pagure.io (opens new window)
- https://framagit.org (opens new window)
- https://git.hit.edu.cn (opens new window)
- 软件相似度比较 https://copycat.gitee.com (opens new window)
Gogs
- https://github.com/gogs/gogs (opens new window)
- https://hub.docker.com/r/gogs/gogs (opens new window)
- 安装教程 (opens new window)
Gitea
- https://github.com/go-gitea/gitea (opens new window)
- https://hub.docker.com/r/gitea/gitea (opens new window)
# GitLab
root用户登录,右上角头像,Settings -> Preferences -> Localization -> Language,选择“简体中文”即可。 高版本的GitLab自带了中文语言包,可以通过上述方式直接切换。如果找不到该选项,表示你的版本还不支持。只能通过安装中文插件进行汉化。
- https://gitlab.com/xhang/gitlab/wikis/home (opens new window)
- GitLab Community Edition (中文社区版) (opens new window)
- https://hub.docker.com/r/bensonfx/gitlab-ce-zh (opens new window)
- https://github.com/bensonfx/codeserver (opens new window)
- https://hub.docker.com/r/benyoo/gitlab (opens new window)
- https://hub.docker.com/r/imleafz/gitlab-ce-zh (opens new window)
- https://crowdin.com/project/gitlab-ee (opens new window)
- clone所有项目 https://github.com/huchao1009/gitlab-projects-clone (opens new window)
- https://git.openldap.org (opens new window)
- https://gitlab.com/gitlab-org/gitlab-runner (opens new window)
version: '2'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh:11.1.4'
restart: unless-stopped
hostname: 'git.woetu.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://git.woetu.com'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
# 需要配置到 gitlab.rb 中的配置可以在这里配置,每个配置一行,注意缩进。
# 比如下面的电子邮件的配置:
# gitlab_rails['smtp_enable'] = true
# gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
# gitlab_rails['smtp_port'] = 465
# gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
# gitlab_rails['smtp_password'] = "password"
# gitlab_rails['smtp_authentication'] = "login"
# gitlab_rails['smtp_enable_starttls_auto'] = true
# gitlab_rails['smtp_tls'] = true
# gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
ports:
- '8099:80'
- '442:443'
- '22:22'
volumes:
# - /home/gitlab/config:/home/gitlab/config
# - /home/gitlab/data:/home/gitlab/data
# - /home/gitlab/logs:/home/gitlab/logs
- config:/etc/gitlab
- data:/var/opt/gitlab
- logs:/var/log/gitlab
volumes:
config:
data:
logs:
# GitHub
- GitHub漫游指南 https://github.com/phodal/github (opens new window)
- 首次贡献 https://github.com/firstcontributions/first-contributions (opens new window)
- https://github.com/all-contributors/all-contributors (opens new window)
- https://github.com/probot/probot (opens new window)
- https://help.github.com/cn (opens new window)
- 发布成功之后
github pages
的Custom domain
配置项就被清空:github-pages-basics (opens new window) - https://codecov.io (opens new window)
- 目录 - P3TERX ZONE (opens new window)
- https://github.com/tiimgreen/github-cheat-sheet (opens new window)
- https://github.com/zenodo/zenodo (opens new window)
- 手动同步fork https://blog.blueskyclouds.com/jsfx/58.html (opens new window)
- https://github.com/wei/git-sync (opens new window)
- https://github.com/repo-sync (opens new window)
- 自动同步fork https://github.com/wei/pull (opens new window)
- GitHub的Java API https://github.com/hub4j/github-api (opens new window)
- 项目管理 https://www.zenhub.com (opens new window)
统计
- GH存档 https://www.gharchive.org (opens new window)
- https://github.com/kon9chunkit/GitHub-Chinese-Top-Charts (opens new window)
- GitHub每周趋势 https://github.com/SolaTyolo/gold_github_trending (opens new window)
- GitHub每天趋势 https://github.com/yangwenmai/github-trending-backup (opens new window)
- https://github.com/HelloGitHub-Team/Article (opens new window)
- https://github.com/tophubs (opens new window)
- 记录GitHub趋势 https://github.com/xiaobaiha/github-trending-history (opens new window)
- https://github.com/GitHubDaily (opens new window)
- https://github.com/techgaun/active-forks (opens new window)
- https://giters.com (opens new window)
- 获取统计信息 https://github.com/shroudedcode/devstats (opens new window)
- 获取动态生成的GitHub统计信息 https://github.com/anuraghazra/github-readme-stats (opens new window)
- 获取访问统计 http://profile-counter.glitch.me/用户名/count.svg
- 历史Star数 https://starchart.cc/用户名/My-Actions.svg
- 你在 GitHub 上看到过的最有意思的项目是什么? - 知乎 (opens new window)
# 访问速度过慢
可以使用
git config --global url."github.com".insteadOf hub.fastgit.org
来替换url
- php源码 https://github.com/ilanyu/offline-download (opens new window)
- go源码 https://github.com/ilanyu/offLineDownloader (opens new window)
- https://github.com/churuxu/xdownload (opens new window)
- https://github.com/fhefh2015/Fast-GitHub (opens new window)
- https://myssl.com/dns_check.html (opens new window)
- http://tool.chinaz.com/dns (opens new window)
- https://www.ipaddress.com (opens new window)
- https://greasyfork.org/zh-CN/scripts/412245 (opens new window)
- https://trli.coding.net/public (opens new window)
- https://github.com/Potterli20/hosts (opens new window)
- https://gitee.com/organizations/mirrors_trending/projects (opens new window)
- https://gitee.com/docmirror/dev-sidecar (opens new window)
- https://codechina.csdn.net/mirrors (opens new window)
- https://gitee.com/mirrors (opens new window)
- https://github.com/FastGitORG (opens new window)
- https://github.com/dotnetcore/FastGithub (opens new window)
- https://github.com/hunshcn/gh-proxy (opens new window)
- https://d.serctl.com (opens new window)
- https://github.xxyyzz.workers.dev (opens new window)
- https://gh.msx.workers.dev (opens new window) 美国
- https://gh.xiu2.xyz (opens new window) 美国(自建
- https://gh.argv.cc (opens new window) 美国
- https://git.yumenaka.net (opens new window) 美国
- https://download.fastgit.org (opens new window) 日本
- https://gitclone.com 中国浙江 (opens new window) 中国浙江
- https://github.com.cnpmjs.org (opens new window) 新加坡
Git Clone SSH 加速
git@git.zhlh6.cn
中国北京git@hub.fastgit.org
中国香港
Raw 文件加速
- https://cdn.jsdelivr.net (opens new window) 中国国内
- https://raw.fastgit.org (opens new window) 中国香港
- https://cdn.staticaly.com (opens new window) 日本东京
刷新DNS缓存
# macOS
killall -HUP mDNSResponder
dscacheutil -flushcache
# Windows
ipconfig /flushdns
# Linux
service nscd restart
# Ubuntu
sudo /etc/init.d/dns-clean start
克隆代理地址
- https://github.com/BaseMax/GitHubMirror (opens new window)
- https://github.com/RC1844/FastGithub (opens new window)
- 替换
github.com
为github.com.cnpmjs.org
jlytgs.com/github_
github.dyf62976.workers.dev
github.wuyanzheshui.workers.dev
github.hsmw.workers.dev
github.reycn.workers.dev
github.itzmx.com
# Actions
生成公钥和私钥
ssh-keygen -t rsa -b 4096 -C "yourname@example.com" -f 文件名称 -N ""
(ACTION_DEPLOY_KEY), 或者生成新的个人访问令牌(PERSONAL_TOKEN)https://github.com/settings/tokens/new (opens new window)
- https://github.com/actions (opens new window)
- https://github.com/topics/github-pages (opens new window)
- https://github.com/topics/gh-pages (opens new window)
- https://github.com/topics/deploy (opens new window)
- https://github.com/topics/deployment (opens new window)
- https://github.com/topics/github-actions (opens new window)
- https://github.com/topics/github-action (opens new window)
- https://github.com/sdras/awesome-actions (opens new window)
- https://github.com/topics/workflow (opens new window)
deploy-to-github-pages
、pages
、deploy
- https://github.com/peaceiris/actions-gh-pages (opens new window)
- https://github.com/JamesIves/github-pages-deploy-action (opens new window)
upload release
- https://github.com/wangyoucao577/go-release-action (opens new window)
- https://github.com/elgohr/Publish-Docker-Github-Action (opens new window)
- https://github.com/release-drafter/release-drafter (opens new window)
- https://github.com/xresloader/upload-to-github-release (opens new window)
- https://github.com/svenstaro/upload-release-action (opens new window)
第三方CI
- CI services (opens new window)
- https://github.com/opencpu (opens new window)
- https://github.com/circleci (opens new window)
- https://github.com/codeship (opens new window)
- https://github.com/gocd (opens new window)
- https://github.com/travis-ci (opens new window)
- https://github.com/wercker (opens new window)
# GitWebHook
- 手动部署: Vue项目完成后,执行
npm run build
,然后将生成的dist目录下的文件放到web目录下
WebHooks自动化部署,流程如下:
- 配置
Gitea
的WebHook
通知(也可以用码云
、Github
、GitLab
、gogs
,带WebHook
功能就行) - 当我们
push
到仓库时,Gitea
会主动发送一个通知到我们的服务器,然后服务器接到通知执行我们部署的脚本,开始自动化构建。
- https://github.com/bajins/webhook-go (opens new window)
- https://github.com/adnanh/webhook (opens new window)
- https://github.com/pre-commit (opens new window)
# 配置接收通知
必备环境
- 以下命令视自己的环境而执行
# git
yum install -y git
# node 由于nodejs自带npm所以就不需要手动安装了
yum install -y nodejs
# vue-cli
npm install -g @vue/cli
# 宝塔面板
- 设置宝塔WebHook插件
宝塔WebHook获取url
param参数需要和脚本里对应起来,我这里写的是pull
http://服务器ip:8888/hook?access_key=5C84B7A5UeXYalfNL6WEpi3jdmmxhFlk3jpvEw02BMo84Ak3¶m=pull
# netcat命令
实现监听端口->响应请求->执行脚本部署
一直监听 9999 端口,有请求就响应
echo
的内容,并执行指定脚本
echo -e "HTTP/1.1 200 ok,glass\r\nConnection: close\r\n\r" | nc -l 0.0.0.0 9999 ; sh /home/update.sh >> /home/logs/webhook.log 2>&1
通过 systemd,可以将这个脚本管理起来,让它永远重启,这样一次部署之后,马上就可以重新监听,等待下一次部署命令。注意要添加 StartLimitInterval ,限制一下执行的频率。
- 最终的
systemd service
如下
[Unit]
Description=Autopull through webhook
After=network.target
[Service]
User=admin
Type=simple
ExecStart=/bin/bash -xc 'echo -e "HTTP/1.1 200 ok,glass\r\nConnection: close\r\n\r" | nc -l 0.0.0.0 9999 ; sh /home/deploy/update.sh >> /home/logs/webhook.log 2>&1'
Restart=always
StartLimitInterval=1min
StartLimitBurst=60
[Install]
WantedBy=multi-user.target
这样就可以实现每次向 master push 代码,自动测试成功并且马上推送到测试环境中。 update.sh 脚本的最后可以加一个 Curl 命令向钉钉或者 slack 发送提醒。
# 配置WebHook
# 添加接收通知url
# 测试推送
# 安装最新版
- 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': bajins
Password for 'https://bajins@github.com':
To https://github.com/bajins/test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/bajins/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
可以允许不相关历史提,强制合并