通用
ssh-keygen -t rsa -C "954241552@qq.com"
git config --global user.name "zhaoyz"
git config --global user.email 954241552@qq.com
https://git-scm.com/book/zh/v2
《Git版本控制管理》(第二版) 出版时间: 2015-3 豆瓣评分: 7.3(66人评价)
《Git权威指南》出版时间: 2011-6-27 豆瓣评分: 8.0(471人评价)
《GitHub入门与实践》出版时间: 2015-7 豆瓣评分: 7.8(496人评价)
https://www.liaoxuefeng.com/wiki/896043488029600
git commit 技巧
:star:
、:bug:
、:hammer:
可以显示图标
git init
:将当前目录变成 git 可以管理的仓库
创建dev分支 : git branch dev
切换到dev分支 : git checkout dev
创建并切换到dev分支 : git checkout -b dev
删除dev分支 : git branch -d dev
推送dev分支 : git push origin dev
退出git log
: 输入q
基本概念
git commit
修改 commit 信息: git commit --amend
git rebase
多次无用的 commit 就很让人不舒服。可能很多人觉得无所谓,无非是多了一些提交纪录。
导致的问题:
- 不利于代码 review
- 会造成分支污染: 如果有一天线上出现了紧急问题,你需要回滚代码,却发现海量的 commit 需要一条条来看
git rebase 如果冲突
需要先解决冲突
然后执行 git add -A
然后 git rebase --continue
然后才能 push
如何合并多次提交纪录
我们来合并最近的 4 次提交纪录,执行:
1 |
|
git clone
git clone --depth=1 xxx
git clone --depth=1
之后拉取其他分支:
1 2 3 |
|
再重新切回 master:
1 2 |
|
push 失败
1 |
|
1 2 3 4 |
|
原因: 使用了 rebase, push 时需要加 -f
参数
The -f is actually required because of the rebase.
Whenever you do a rebase you would need to do a force push because the remote branch cannot be fast-forwarded to your commit.
You'd always want to make sure that you do a pull before pushing, but if you don't like to force push to master or dev for that matter, you can create a new branch to push to and then merge or make a PR.
https://stackoverflow.com/questions/39399804/updates-were-rejected-because-the-tip-of-your-current-branch-is-behind-its-remot
fetch
1 2 3 4 |
|