git 合并代码 单个或多个commit

130 阅读1分钟

1.合并两个分支的部分commit

1.在分支1 正常提交push代码  
2.分支1 git log 赋值要合并的提交 commit版本号  
3.切换分支2上 首先git pull  
4.分支2 git cherry-pick  commit版本号  
5.分支2 git push 仓库就可看到已合并到最新分支  
合并多个commit,空格分开    git cherry-pick  commit版本号1  commit版本号2

2.合并两个分支代码

修改完代码后,准备提交代码:

在develop分支下:
1.git status 查看修改哪写文件
2.git stash 暂存
3.git pull 拉取线上代码
4.git stash pop 取出暂存文件
5.git add .
6.git cz 
7.git push 将代码提交到线上develop分支
8.git checkout release 切换到release 分支 或git switch release (尽量用switch,因为checkout可能会新建)
9.git pull  (非常重要!非常重要!非常重要!)
10.git merge develop    把develop 合并到release 分支上
11.git push 将代码提交到线上release 分支 (push完记得切换会dev分支!!!!)

安装git教程

https://blog.csdn.net/weixin_46474921/article/details/127091723

回退提交
git rest --hard HEAD^ 回退到上一个版本
git rest --hard 版本号  回退到制定版本

3.拉取远程分支到本地

git fetch origin 分支名:分支名

切换分支

git switch 分支名

4.退出rebase模式

git rebase --abort