02-workflow

0. cmd

# 1. 远程仓库
git remote show origin
git remote rename dev dev2
git remote rm dev

git remote -v
git remote add origin <项目地址>
git remote rm origin

# 删除远程分支
git push origin --delete <branchName>
# 1. 增加本地分支
git branch temp
# 2. 删除本地分支
git branch -d temp

# 3. 设置存在的跟踪分支
git branch -u origin/serverfix
git branch --set-upstream-to
git branch -vv
# 1. 远程跟踪分支
# 创建并切换
git checkout -b serverfix origin/serverfix
git checkout --track origin/server
git checkout serverfix
# 1. refusing to merge unrelated histories
git pull origin master --allow-unrelated-histories

# 2. 推送
git push <远程主机名> <本地分支名>:<远程分支名>
git push <远程主机名> <本地分支名>
# git取消文件跟踪
# 1. 取消全部
git rm -r --cached .
git add .
git commit -m 'update .gitignore'

# 2. 取消单个文件
git rm --cached readme1.txt

# 3. 取消所有target目录
git rm -r -n --cached target/

# 4. git commit 关闭eslint校验
.eslintignore文件,忽略src文件
# 7. 查看各分支当前所指对象
git log --oneline --all -graph
git log --oneline --decorate
git log --oneline --decorate --graph --all
 # 1. 输入用户名和密码的问题解决
git config --global credential.helper store
git fetch XXX

1. new_clone

1. 切换到指定分支

  • 场景:刚刚clone下来远程仓库,需要切换指定dev分支
git clone http://192.168.*.*/ooxx.git

cd ooxx

# 直接检出,本地不存在的远程分支
git checkout dev





 

2. 账号无权限访问仓库

➜  ooxx# git clone http://gitlab.listao.com/ooxx.git
Cloning into 'ooxx'...
remote: The project you were looking for could not be found.
fatal: repository 'http://gitlab.listao.com/ooxx.git/' not found


 
 
  • url中添加账号,后输入密码即可
➜  ooxx# git clone http://lisongtao@gitlab.listao.com/ooxx.git
Cloning into 'ooxx'...
Password for 'http://lisongtao@gitlab.listao.com':
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 56 (delta 11), reused 0 (delta 0)
Unpacking objects: 100% (56/56), 4.89 MiB | 21.88 MiB/s, done.


 





  • URL中已经携带了账号信息,任何客户端(idea、sourceTree)可以正常操作
➜  ooxx git:(master)# git remote show origin
* remote origin
  Fetch URL: http://lisongtao@gitlab.listao.com/ooxx.git
  Push  URL: http://lisongtao@gitlab.listao.com/ooxx.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)


 
 







2. ignore_file

1. 取消跟踪

  • 场景:取消对指定文件(夹)的跟踪
➜  listao_boot git:(master)# pwd
/Users/listao/mca/listao_boot

# 列出需要取消跟踪的文件,不会删除文件
# -r:递归
# -n:列出文件
➜  listao_boot git:(master)# git rm -r -n --cached tmp/src/ooxx.txt
rm 'tmp/src/ooxx.txt'

➜  listao_boot git:(master)# git rm -r --cached tmp/src/ooxx.txt
rm 'tmp/src/ooxx.txt'
image-20240609202116373
image-20240609202202539

2. .gitignore

# 具体文件
/design_pattern/tempFile.obj

# 具体目录。左`/`:代表父级目录
/server/target/

# 匹配目录(项目下所有target目录)
target/

3. .git/info/exclude

  • .gitignore:在团队成员中共享,文件被公认为“无需版本控制”
  • .git/info/exclude:文件仅供个人专用的,不用版本控制时

3. add remote

  • 添加远程仓库
# 查看指定远程仓库详情
git remote show origin

# 添加远程仓库url
git remote add origin http://ip:port/tt/listao_doc.git

# 准备好本地推送分支
git checkout -b main

# 强制推送本地分支到远程
git push -u origin master:main -f
image-20240324101801595

4. reset

前进、后退历史版本

  • 复制:在终端中选中就是复制了
  • 粘贴:右键 + paste
image-20240609161418547

1. hard

  • 最常用(放弃当前所有修改)
  • 本地库指针移动。清空暂存区,清空工作区
➜  tmp git:(master)# git reset --hard 24b15ab39
HEAD is now at 24b15ab ooxx
image-20240609161543521
image-20240609161517248

2. mixed

  • 本地库指针移动。清空暂存区,改变工作区(当前状态 - 回退版本)
image-20240609161932075

3. soft

  • 本地库指针移动。改变暂存区(当前状态 - 回退版本),清空工作区
image-20240609162004708

5. 切换账号

  • yushaowei账号被禁用,git的记忆清除
# 1. 最有效。再次Git操作,输入正确用户名,密码即可
git config --system --unset credential.helper

# 2. 再次Git操作,输入正确用户名,密码即可
git config –global http.emptyAuth true

# 3. 每次pull/push都密码
git config --global credential.helper store

6. git放弃修改

git checkout -f

98. ssh协议

1. 生成公钥 && 私钥

ssh-keygen -t rsa -C "***@qq.com"
image-20220711164647778

2. pub添加到gitlab

SC9BL0toRG1waWFYRGhZajNNVmhhVTEwdUhKdFplWWZQYmJaS3BjPQ==

3. pub添加到github

image-20220711165506607

4. 一台电脑多个公钥

99. bug

1. git安装路径查询

which git

2. github无法clone

背景:

  1. https://github.com/open in new window ,页面可以访问
  2. git clone https:// ,无法clone
  3. ping github.comopen in new window 也不通

1. 查询真实ip

resolve:

  1. 查询 github.comopen in new window 域名对应的ip,https://ipaddress.com/website/github.com
  2. sudo vim /etc/hosts,末尾加上 <140.82.113.3 github.comopen in new window>

2. 配置port

image-20220711165748681
# 配置git代理
git config --global http.proxy 127.0.0.1:1087

# 查看git配置
git config --list

# 恢复默认配置
git config --global --unset http.proxy

3. personal access token

image-20220711165830121
image-20220711165841124
image-20220711174149041
image-20220711174229002

4. Repository not found

remote: Repository not found.
fatal: repository 'http://10.68.7.177/xxx/xxx.git' not found
  • 出现此错误是因为本地已经保存过之前项目的权限信息--账号/密码,但是该账号密码对于想要拉取代码的项目权限不匹配,因此需要在拉取代码时添加具有权限的账号密码:
  • 打开terminal执行:git clone http://username:password@10.68.7.177/xxx/xxx.git
  • 如此即可解决。

5. gitee

  • 仓库过大,GC仓库
image-20240605170104592