git commit 合并版本-- git rebase

1、目标:

将前几个版本合并到当前版本上

2、实现方法:

2.1 查看并保存历史记录

git log

将log复制出来,方便误操作后的找回

2.2 合并历史版本

git rebase -i HEAD~4

2.3 合并历史版本的hash信息

  1. 保留base 的hash值信息
  2. 第2至4行pick 改为 squash
  3. version 4 为最新版本
pick ecd730c test version 1   xxxxxxxxx
squash ecd750d test version 2   xxxxxxxxx
squash ecd730e test version 3   xxxxxxxxx
squash ecd750f test version 4   xxxxxxxxx

# Rebase 0e3cdef..ecd730c onto 0e3cdef (1 command)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

2.3 合并历史版本的commit信息

删掉不需要的commit信息

3 查看并同步到仓库

3.1 检查分支commit历史

git log 检查提交历史

3.2 提交仓库

3.2.1 远端未提交

直接提交分支

git push branch1

3.2.2 远端已提交

合并的版本号比提交的旧

  1. 远端删除分支
git push origin --delete <BranchName>
  1. 重新提交分支
git push -u origin master

本地删除一个提交版本

git reset --hard HEAD~1
git branch -d <BranchName>

3.3 在新版本上提交并覆盖当前版本

该操作会改变你原来的commit id

$ git commit --amend

3.4 远端强制更新提交

$ git push --force-with-lease origin master
git push -f
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容