生而为人

程序员的自我修养

0%

[3/24 10:17] Bolun YaoNew Bing又增加了什么神奇的监测机制,现在挂私人梯子完全上不去了
今天之前还没什么问题,现在会被疯狂redirect到“国内版”,即便偶尔打开 chat 一次也会报错 looks like your network settings are preventing access to this feature.
全局也没用了,这怎么检测到的

[3/24 10:50] Ray Sun
清 cookie,或者 ?mkt=en-US ?
​[3/24 10:51] Ailing Ji
我倒是不会,你是关闭过浏览器吗,设置一下url参数:setlang=en&cc=us
<https://teams.microsoft.com/l/message/19:9268e0678e654fc1a8965e739a1859ec@thread.skype/1679626207358?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&amp;groupId=2e06e852-2e42-4acb-a366-5df01ee87a68&amp;parentMessageId=1679624261164&amp;teamName=Suzhou Life&channelName=General&createdTime=1679626207358&allowXTenantAccess=false>
关闭浏览器试过了,清cookie 和 mkt 还没试。不过有个更根本的问题是即便想办法打开 chat 也会报错 looks like your network settings are preventing access to this feature.
貌似最近有些 IDC 的 IP 段也被 new bing ban 了,可以在梯子上套一层 cloudflare warp

推荐chatgpt。用公司的 150刀 azure credit,把chatgpt 和 speech recognition, text to speech 连起来,就是一个超棒的英语口语陪练了

规则引擎:

easyRule

[toc]

标准流程

  1. 添加暂存区git add .()

克隆

新仓库

1
2
3
4
5
git checkout -b dev(本地分支名称) origin/develop(远程分支名称)

error log:
fatal: 'origin/MTSparkMSNv2' is not a commit and a branch 'users/jingqicao/M2B_V2' cannot be created from it
need run git pull to update.

克隆过仓库,拉取新分支

1
2
3
4
5
6
7
8
# 先获取远程最新信息
git fetch origin

# 基于远程 dev 分支,在本地创建并切换到 dev
git checkout -b dev origin/dev

# 更简洁的写法(Git 2.23+)
git switch dev

本地已有分支

1
2
3
4
5
6
7
8
9
10
11
12
1. 如果本地已经克隆过,只是想获取远程最新改动:

# 进入仓库目录
git checkout targetBranch
# 拉取并合并到当前分支
git pull

2. 如果想拉取但不自动合并(先查看再决定):

git fetch
git log HEAD..origin/main --oneline # 查看差异
git merge origin/main # 确认后再合并

分支

查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1. 查看所有远程分支
git branch -r # 显示的是本地缓存的远程分支列表
git branch -r -v # 远程分支详细信息(含最新提交)

2. 查看所有最新的远程分支
git fetch --all
# 或者
git fetch origin
# 然后再执行
git branch -r

3. 查看所有分支(含本地和远程)
git branch -a

4. 查看远程分支的 URL 和跟踪关系
git remote show origin

删除

1
2
1. 清理掉本地已失效的远程分支引用
git fetch --prune

Git 操作——如何删除本地分支和远程分支

新分支push到远端

1
2
3
git push --set-upstream origin users/jingqicao/performance-optimize
// 需要保证本地分支名称与指定的remote分支名称完全相同,否则
error: src refspec users/jingqicao/performance-optimize does not match any

拉取远程分支

1
2
3
4
5
6
7
8
9
10
1. 拉取远程所有分支的最新信息(但不合并)
git fetch --all

2. 拉取远程分支但不想自动合并(先看看再决定)
git fetch origin dev
git log HEAD..origin/dev --oneline # 查看差异
git merge origin/dev # 确认后再合并

3. 拉取远程分支但不切换过去,当前分支不变
git fetch origin dev:dev

本地关联远程分支

1
2
3
4
5
6
7
8
9
10
11
1. push同时关联
git push --set-upstream origin xxx

2. 关联已经存在的
git branch --set-upstream-to=origin/dev

3. 重新关联
# 切换到该分支(如果不在的话)
git switch feature/login
# 将当前分支强制重置为远程分支的状态(注意:这会丢弃本地的所有未推送提交!)
git reset --hard origin/feature/login

本地切换远程分支

1
2
3
4
5
6
7
8
9
1. git 2.23+
# 1. 先从远程仓库拉取最新的分支引用信息
git fetch
# 2. 直接切换到远程分支(git 会自动识别 origin/分支名)
git switch 远程分支名

2. git 2.23-
git fetch
git checkout -b 本地分支名 origin/远程分支名

内容

撤销修改

1
2
3
// 这是一个危险的操作,会撤销指定文件或全部文件的所有本地修改
git checkout -- <file>
git checkout -- .

提交(commit)

1
2
3
4
5
6
7
git commit -m ""

git commit -am ""
追加commit注释,一次push不会生成多个commit节点

git commit --amend
可以修改最近一次commit的注释

查看当前commit

1
git log

对比两个commit(两个commit可以来自不同分支)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
hash2 在 hash1上的修改
git diff commit-hash1 commit-hash2 --stat

如果想进一步查看test修改了那些地方:
只需将 git diff hash1 hash2 --stat 中的 --stat改为具体的文件即可

如果想将两次提交的差异部分提取成补丁文件
git diff hash1 hash2 filename > patch_name

如果想将多个文件的差异生成到同一patch文件 则:
git diff hash1 hash2 filename1 filename2 > patch_name

使用工具(左右两个commit,对应了difftool的左右窗口):
git difftool 199b8598f422485e453f1e4e87aaa6176ff48ad0 4b97457217e29355ddeff0aec8562271c06ac6fe --stat

对比两个分支

1
2
3
4
git diff users/jingqicao/temp-master master --name-status
可以展示变更文件的全路径

git diff-tree
  1. Git 修改已提交的commit注释

杂项

关闭difftool的使用询问:

1
2
3
4
5
询问:
Launch 'default-difftool' [Y/n]

关闭:
git config --global difftool.prompt false

[toc]

编辑

删除工作区某个文件,或某个目录的改动

1
2
git checkout <file-name>
git checkout <path-name>

查看

#如何使用git比较两次commit之间的差异文件

1
2
3
git diff hash1 hash2
hash2是后提交的commit
即hash1是被对比commit,diff结果是hash2在hash1上的改动

查看本地分支关联的远端分支

1
git branch -vv

[toc]

安装步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
1. 生成 SSH 密钥,一路回车即可,默认保存在 ~/.ssh/id_ed25519
ssh-keygen -t ed25519 -C "你的邮箱@example.com"

2. 查看公钥并复制
cat ~/.ssh/id_ed25519.pub

3. 添加到 GitHub:
进入 GitHub → Settings → SSH and GPG keys → New SSH key,粘贴公钥内容保存。

4. 测试连接
ssh -T git@github.com

5. 拉取某个分支
git clone -b 分支名 https://github.com/用户名/仓库名.git

.gitconfig

git 添加别名的方式,打开~/.gitconfig文件在其末尾添加:
在命令行输入以下命令:
1、进到根目录
cd ~/
2、打开.gitconfig,
vi ~/.gitconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[alias]
a = add
b = branch
c = commit
d = diff
l = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset | %C(bold)%an' --abbrev-commit --date=relative
r = reset
aa = add .
ba = branch -a
ca = commit -a
cc = commit -a -m
cl = clone
cm = commit -m
co = checkout
cp = cherry-pick
nb = checkout -b
pl = pull
ps = push origin master
st = status

[user]
name = jingqicao
email = cjqzhuce@126.com

[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
[difftool]
prompt = false