- 假设当前分支为test1,按时间顺序进行了三次提交:commit1、commit2、commit3
1、git rebase master
将master的改动作为一次commit添加到当前分支
2、git rebase --abort
停止rebase操作
3、git rebase -i (commitId1) [commitId3]
将commitId1至commitId3的commit合并。前开后闭。
合并区间包括commitId2、commitId3。
vim 编辑器中 i 插入:pick commitId2;squash commitId3。esc后:wq。vim编辑器中编写三次提交信息。
git push -f
如果遇到冲突,解决冲突后,使用git rebase --continue
4、git pull --rebase
git pull 默认是git fetch + merge
5、git reset --hard commitId2
回退到commitId1的版本,git log中只有commit1
-
git rebase -i
-
git reset --hard origin/beta
-
git cherry-pick [commit id]
-
git revert
-
git fetch
-
git reset --hard origin/beta
git rebase --abort
merge && rebase
-
merge 会多一次commit
-
rebase
-
A: [main][commit1][commit2]
-
B: [main][commit3][commit4]
-
A rebase B: [main][commit3][commit4]—[commit1][commit2]
- rebase相当于用[main][commit3][commit4]替换了A中的[main]
-
A merge B: [main][commit1][commit2]—[merge commit]
-
merge相当于把所有的[main][commit3][commit4]作为一次提交接在A后面
-
使用gitlab
-
用github的账号登录gitlab后,gitlab会提示添加ssh。
-
重新生成ssh时显示本地已生成,目录是C:\Users\dell.ssh,将id_rsa.pub复制到gitlab上即可。
1、从main分支拉了3个分支:test1、test2、test3
2、test1提交了3次:t1-commit1、t1-commit2、t1-commit3
3、test2提交了1次:t2-commit1
4、test3提交了1次:t3-commit1
5、test1提交了第4次:t1-commit4
6、test1新建merge request,合入main
7、test2: git merge main
8、test3: git rebase main
9、 在test2分支上将最后的3个commit合成一个:git rebase -i 48ea83f99068
-
好像是不能合并不同分支的commit,如果合并不同分支的commit,会存在问题,
-
git rebase --abort
放弃合并,回到rebase操作之前的状态,之前的提交的不会丢弃;
10、在test2分支上提交:t2-commit2、t2-commit3、t2-commit4
11、在test2上合并t2-commit4和t2-commit3: git rebase -i 9415e49ea42
i
可以插入,即insert,然后将第二个pick修改为s
- 改好后按下
esc
退出编辑,然后:wq
- 继续
:wq
,然后git log就可以看到两个commit已经合为一个commit了
- 查看分支视图的命令
git log --graph --decorate --oneline --simplify-by-decoration --all
git log --graph --decorate --oneline --all
- test3分支的本地分支和远程分支指向不一样,test3在rebase main后没有进行过其他操作,