Git 常用命令与常见问题
Git 阅读材料
- Pro Git 看到所有的网站都推荐阅读这一本书,当作手册来查;
- Missing
CS 介绍了 Git 的数据模型,方便理解 Git
不那么友好的指令操作,很惊讶作者可以把 Git 讲得那么清楚;
- btw,该网站同样推荐了许多 Git 的阅读材料,比如下一条:
- Git commit 介绍撰写 Commit 信息的好的实践方案
Git commit 七准则
这里引用 Git commit 里的文字:
- Separate subject from body with a blank line 将主题与正文用空白行分隔
- Limit the subject line to 50 characters 主题限制在 50 个字符之内
- Capitalize the subject line 主题首字符大写
- Do not end the subject line with a period 主题结尾不要写句号
- Use the imperative mood in the subject line 主题使用祈使语气
- Wrap the body at 72 characters 正文每一行不超过 72 个字符
- Use the body to explain what and why vs. how 使用正文说明是什么,为什么,怎么做
Github clone 失败
使用 Github 克隆某一个库的时候,报错如下:
git clone fatal unable to acces
使用如下解决方案
1 | git config --global --unset http.proxy |
结果不行,后来浏览到一篇帖子,说是 Git 端口和本机系统代理的端口不一致造成的。打开 Clash,查看我的笔记本的代理端口为:7890。然后设置 Git 的端口:
1 | git config --global http.proxy http://127.0.0.1:7890 |
注意,第二条是 http://127.0.0.1:7890
,不是
https://127.0.0.1:7890
Git 相关命令
git init
初始化 git 仓库。在当前目录下会生成一个
.git/
目录
git branch <newbranch>
创建一个新的分支(但 head
指针仍然指向旧分支)
git checkout <branchname>
将 head
指针移到某一个分支上