241 lines
6.7 KiB
Markdown
241 lines
6.7 KiB
Markdown
---
|
||
title: Git
|
||
date: 2023-10-23 10:30:31
|
||
author: 文永达
|
||
top_img: https://gcore.jsdelivr.net/gh/volantis-x/cdn-wallpaper/abstract/67239FBB-E15D-4F4F-8EE8-0F1C9F3C4E7C.jpeg
|
||
---
|
||
|
||
|
||
|
||
# Git
|
||
|
||
## Git 全局设置:
|
||
|
||
```shell
|
||
git config --global user.name "username"
|
||
git config --global user.email "email"
|
||
```
|
||
|
||
## 拉取项目
|
||
|
||
```shell
|
||
git clone <url>
|
||
```
|
||
|
||
## 创建 git 仓库:
|
||
|
||
```shell
|
||
mkdir aaa
|
||
cd aaa
|
||
git init
|
||
touch README.md
|
||
git add README.md
|
||
# 添加当前目录下全部文件
|
||
git add .
|
||
git commit -m "first commit"
|
||
git remote add origin https://gitee.com/wenyongda/aaa.git
|
||
git push -u origin master
|
||
```
|
||
|
||
## 已有仓库
|
||
|
||
```shell
|
||
cd existing_git_repo
|
||
git remote add origin https://gitee.com/wenyongda/aaa.git
|
||
git push -u origin master
|
||
```
|
||
|
||
## 查看作者名称、作者邮箱
|
||
|
||
```shell
|
||
git config user.name
|
||
git config user.email
|
||
git config --list
|
||
```
|
||
|
||
## 解决Git提交失败,提示用户密码错误
|
||
|
||
remote: [31m[session-8b4b799a] wenyongda: Incorrect username or password (access token)[0m
|
||
|
||
首先查看C盘下gitconfig配置文件配置
|
||
|
||
```properties
|
||
[core]
|
||
autocrlf = true
|
||
[user]
|
||
name = 文永达
|
||
email = bmdzh11713@163.com
|
||
[difftool "sourcetree"]
|
||
cmd = 'C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe' \"$LOCAL\" \"$REMOTE\"
|
||
[mergetool "sourcetree"]
|
||
cmd = 'C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe' -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
|
||
trustExitCode = true
|
||
[credential "https://gitee.com"]
|
||
provider = generic
|
||
```
|
||
|
||
查看user下的password正不正确,如果没有设置转到控制面板
|
||
|
||
Windows下 `Win + R`运行输入`control`
|
||
|
||
用户账户 -> 凭据管理器 -> 管理 Windows 凭据 -> 普通凭据
|
||
|
||
编辑 git:https://gitee.com下的用户名和密码
|
||
|
||
如果没有手动添加,并在Git Bash中执行
|
||
|
||
```shell
|
||
git config --global credential.helper wincred
|
||
```
|
||
|
||
## 储藏 (Stash)
|
||
|
||
```shell
|
||
git stash
|
||
|
||
git stash list
|
||
```
|
||
|
||
|
||
|
||
## SSH提交
|
||
|
||
1. SSH 秘钥默认储存在账户的主目录下的 ~/.ssh 目录
|
||
如:`C:\Users\用户\.ssh\`
|
||
|
||
查看是否包含id_rsa和id_rsa.pub(或者是id_dsa和id_dsa.pub之类成对的文件),有`.pub 后缀的文件`就是**公钥**,另一个文件则是密钥。
|
||
|
||
如果有这两个文件,则跳过1.2;如果没有这两个文件,甚至.ssh目录也没有,则需要用ssh-keygen 来创建
|
||
|
||
2. ###### 生成密钥信息
|
||
|
||
在`.ssh 目录`下右键打开[Git Bash](https://so.csdn.net/so/search?q=Git Bash&spm=1001.2101.3001.7020)(.ssh目录不存在,则在任一目录下操作,或者手动创建该目录)
|
||
|
||
3. ###### 生成密钥
|
||
|
||
> ssh-keygen -t rsa -C "注释信息(一般为邮箱your_email@youremail.com)"
|
||
|
||
4. 在~/.ssh/下会生成两个文件,id_rsa和id_rsa.pub
|
||
|
||
> id_rsa是私钥
|
||
>
|
||
> id_rsa.pub是公钥
|
||
|
||
5. SourceTree配置
|
||

|
||
启动 **PuTTY Key Generator**
|
||
|
||
6. 依次点击
|
||

|
||
|
||
7. PPKfile version 选择 2
|
||

|
||
|
||
8. 选择之前生成的id_rsa
|
||

|
||
|
||
9. 出现如下,选择 **Save private key** 保存秘钥
|
||

|
||
|
||
10. 保存到 ~/.ssh 目录即可
|
||

|
||
|
||
11. 在 **Sourcetree** 中 **工具** -> **选项** 中选择刚刚保存的 ppk文件即可
|
||
|
||
## 变更SSH pubKey comment
|
||
|
||
> [Change an SSH key comment](https://www.commands.dev/workflows/change_ssh_key_comment)
|
||
|
||
```
|
||
# new_comment 新的注释
|
||
# ssh_key_path ssh私钥路径 ~/.ssh/id_rsa
|
||
ssh-keygen -c -C "new_comment" -f ssh_key_path
|
||
```
|
||
|
||
## 还原变更
|
||
|
||
```shell
|
||
# 指定文件或目录
|
||
git checkout -- <filename or directory>
|
||
```
|
||
|
||
## git 如何关闭commit时的语法检测 ---husky
|
||
|
||
1 报错提示
|
||
git commit提交时报错如下:
|
||
|
||
husky+>+pre-commit+(node+v14.18.2)
|
||
|
||
2 解决方案
|
||
1:卸载husky。只要把项目的package.json文件中devDependencies节点下的husky库删掉,然后重新npm i 一次即可。或者直接在项目根目录下执行npm uninstall husky --save也可以,再次提交,自动化测试功能就屏蔽掉
|
||
|
||
2:进入项目的.git文件夹(文件夹默认隐藏,可先设置显示或者命令ls查找),再进入hooks文件夹,删除pre-commit文件,重新git commit -m ‘xxx’ git push即可
|
||
|
||
3:将git commit -m “XXX” 改为 git commit --no-verify -m “xxx”
|
||
|
||
# github
|
||
|
||
## push/pull老是超时解决方法
|
||
|
||
**设置针对github.com本身(如果你需要代理的仓库,都是github上面的,只要设置这个)的代理:**
|
||
|
||
```shell
|
||
#只对github.com
|
||
# 找到自己的代理的port的4个数字的端口就行,不一定是1080口的
|
||
git config --global http.https://github.com.proxy socks5://127.0.0.1:7890
|
||
#上面是别人的,如果你的代理是http类型的,如下设置:
|
||
git config --global http.https://github.com.proxy 'http://127.0.0.1:代理的port'
|
||
|
||
#取消代理
|
||
git config --global --unset http.https://github.com.proxy
|
||
```
|
||
|
||
**针对所有仓库(包含github.com之外的仓库的代理)**
|
||
|
||
```shell
|
||
# 找到自己的代理的port的4个数字的端口就行,不一定是1080口的
|
||
git config --global http.proxy 'socks5://127.0.0.1:1080'
|
||
git config --global https.proxy 'socks5://127.0.0.1:1080'
|
||
|
||
#上面是别人的,如果你的代理是http类型的,如下设置:
|
||
# 找到自己的代理的port的4个数字的端口就行,不一定是1080口的
|
||
git config --global http.proxy 'http://127.0.0.1:代理的port'
|
||
git config --global https.proxy 'http://127.0.0.1:代理的port'
|
||
```
|
||
|
||
## 解决remote: Support for password authentication was removed on August 13, 2021.
|
||
|
||
1. Github 头像处 **Settings**
|
||
|
||
2. 左侧最下边 **Developer settings**
|
||
|
||
3. 左侧找到 **Personal access tokens**
|
||
|
||
4. 点击展开,找到 **Tokens (classic)**
|
||
|
||
5. 右侧下拉框 **Generate new token (classic)**
|
||
|
||
6. 按以下配置
|
||

|
||
|
||
7. 得到 token
|
||

|
||
|
||
8. 修改现有项目的url
|
||
```shell
|
||
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
|
||
```
|
||
|
||
|
||
|
||
# Gitea
|
||
|
||
## 备份
|
||
|
||
数据库备份至postgresql
|
||
|
||
```shell
|
||
docker exec -u git -it -w /tmp gitea bash -c '/app/gitea/gitea dump --database postgres --config /data/gitea/conf/app.ini'
|
||
```
|
||
|