生而为人

程序员的自我修养

0%

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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for github.com has changed,
and the key for the corresponding IP address 20.205.243.166
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 RSA key sent by the remote host is
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/cjq/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/cjq/.ssh/known_hosts:10
RSA host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
1
2
3
>> ssh-keygen -R github.com			//更新know_hosts中的内容
>> 更新publickey(参考)
>> ssh -T git@github.com // 测试是否能正确连接

Reference:

  1. https://blog.csdn.net/helloasimo/article/details/123778112

编辑

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

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

杂项

关闭difftool的使用询问:

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

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

.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

工作区、暂存区、版本库

link

  • **工作区:**就是你在电脑里能看到的目录。
  • **暂存区:**英文叫 stage 或 index。一般存放在 .git 目录下的 index 文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)。
  • **版本库:**工作区有一个隐藏目录 .git,这个不算工作区,而是 Git 的版本库。

正常编写是在工作区,git add 之后提交到暂存区,git commit之后放到版本库

每次与origin分支对比前,先执行git pull操作,才能获取到远端的最新代码。

[toc]

网络问题

github 网址访问不了

GitHub打不开的解决方案(超简单)

  1. https://sites.ipaddress.com/github.com/
  2. https://sites.ipaddress.com/fastly.net/
  3. https://sites.ipaddress.com/assets-cdn.github.com/

My IP | IP Address Tools | IP Geolocation | Website Traffic Checker

1
2
3
4
5
6
7
8
9
140.82.113.4 github.com
151.101.1.194 github.global.ssl.fastly.net
151.101.65.194 github.global.ssl.fastly.net
151.101.129.194 github.global.ssl.fastly.net
151.101.193.194 github.global.ssl.fastly.net
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com

Mac:

1
2
3
4
sudo vi /etc/hosts

# 刷新DNS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Windows:

1
> ipconfig /flushdns

问题

LF will be replaced by CRLF

1
2
3
4
git config core.autocrlf false
1. true:
2. false:
3. input:

切换分支时 如何保证文件完全与线上一致,即其他分支新加的文件被删掉

命令报错

Author identity unknown

报错信息

1
2
3
4
5
6
7
8
9
10
11
12
13
Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'jingqi@DESKTOP-BKUPVT9.(none)')

解决办法

  1. 按照指导重新设置user.emailuser.name,注意变量名称不要设置错了
  2. git var GIT_AUTHOR_IDENT 验证是否设置成功。

参考资料:

  1. git config doc
  2. Configuring Git to handle line endings

本地运行

1
hexo generate
1
hexo server

服务器部署

1
2
3
hexo clean
hexo d -g
hexo deploy

源码提交

1
2
3
4
git checkout -b blog-source
git add -A
git commit -m "init blog"
git push origin blog-source

参考资料

如何用 Github 搭建博客