GIT压缩多次提交记录为一次
GIT压缩多次提交记录为一次
创建文件夹并进行Git初始化
$ mkdir test-rebase
$ cd test-rebase
$ git init
Initialized empty Git repository in /Users/apple/Develop/git/test-rebase/.git/
添加四次提交记录
# 第一次提交
$ touch a.txt
$ git add .
$ git commit -m 'a'
[master (root-commit) 6bf1717] a1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 a.txt
# 第二次提交
$ touch b.txt
$ git add .
$ git commit -m 'b'
[master 356bfff] b1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 b.txt
# 第三次提交
$ touch c.txt
$ git add .
$ git commit -m 'c'
[master e5e5c05] c1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 c.txt
# 第四次提交
$ touch d.txt
$ git add .
$ git commit -m 'd'
[master edaf5da] d1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 d.txt
查看日志
$ git log
commit 08b1b469a8ed1175013a181f1090521c6d1f126a (HEAD -> master)
Author: xf <x17301932065@163.com>
Date: Fri Apr 23 16:09:28 2021 +0800dcommit 76ce2e10599f86849d4e602f218322185d4e5ed1
Author: xf <x17301932065@163.com>
Date: Fri Apr 23 16:09:16 2021 +0800ccommit 197075cddc4e0a21356ea29cdb39f7f9b9eb39b0
Author: xf <x17301932065@163.com>
Date: Fri Apr 23 16:09:07 2021 +0800bcommit 52389daeceb1e4747b58e6f87a38239c578f633e
Author: xf <x17301932065@163.com>
Date: Fri Apr 23 16:08:58 2021 +0800a
将b到d压缩为一次提交
$ git rebase -i 52389daeceb1e4747b58e6f87a38239c578f633e 08b1b469a8ed1175013a181f1090521c6d1f126a
第一个COMMIT记录id为压缩前的一次记录id,第二个COMMIT记录id为要压缩到的记录id。这里就是将从a过后到d的提交记录进行压缩,即压缩b、c、d提交记录。
执行命令后会弹出如下VIM编辑界面:
pick 197075c b
pick 76ce2e1 c
pick 08b1b46 d# Rebase 6bf1717..edaf5da onto 6bf1717 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
"~/Develop/git/test-rebase/.git/rebase-merge/git-rebase-todo" 29L, 1181C
修改记录,这里保留最后一次提交记录,所以将其改为:
pick 197075c b
s 76ce2e1 c
s 08b1b46 d
保存后结果为:
# This is a combination of 3 commits.
# This is the 1st commit message:b# This is the commit message #2:c# This is the commit message #3:d# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Fri Apr 23 16:09:07 2021 +0800
#
# interactive rebase in progress; onto 52389da
# Last commands done (3 commands done):
# squash 76ce2e1 c
# squash 08b1b46 d
# No commands remaining.
再次修改,使提交记录日志为我们修改的日志(也可以不修改):
# This is a combination of 3 commits.
# This is the 1st commit message:b-压缩后提交记录# This is the commit message #2:# c# This is the commit message #3:# d# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Fri Apr 23 16:09:07 2021 +0800
#
# interactive rebase in progress; onto 52389da
# Last commands done (3 commands done):
# squash 76ce2e1 c
# squash 08b1b46 d
# No commands remaining.
查看当前分支
保存上面提交后,查看分支信息,当前分支并不在master上了,这个分支并不会保存,只是我们压缩提交记录后的一个临时分支:
$ git branch
* (HEAD detached from refs/heads/master)master
创建新分支
基于当前临时分支创建新分支:
git checkout -b new
Switched to a new branch 'new'
查看日志:
git log
commit 3d9e6dabd859310e0c44de3ccbe241e2b7098a01 (HEAD -> new)
Author: ****
Date: Fri Apr 23 16:09:07 2021 +0800b-压缩后提交记录commit 52389daeceb1e4747b58e6f87a38239c578f633e
Author: ****
Date: Fri Apr 23 16:08:58 2021 +0800a
可以看到提交记录就是合并后的记录了。
GIT压缩多次提交记录为一次相关推荐
- 【Git】Git 基础命令 ( 查看提交记录 git log | 版本回滚 git reset | 撤销回滚 git reflog )
文章目录 一.查看提交记录 git log 1.查看详细提交记录 2.查看简略提交记录 二.版本回滚 git reset 1.Git 中的版本表示 HEAD~1 2.版本库代码回滚 三.撤销回滚 1. ...
- git删除所有历史提交记录,只留下最新的干净代码
git删除所有历史提交记录,只留下最新的干净代码 1.Checkoutgit checkout --orphan latest_branch2. Add all the filesgit add -A ...
- Git使用 从入门到入土 收藏吃灰系列 (十四) 清除git仓库的所有提交记录
文章目录 一.前言 二.清除git仓库的所有提交记录 本节速览 清除git仓库的所有提交记录 一.前言 参考安装Git 详细安装教程 参考视频B站 Git最新教程通俗易懂,这个有点长,感觉讲的精华不多 ...
- git删除相关历史提交记录,相关文件保持当前状态
git删除相关历史提交记录,相关文件保持当前状态 引言 新年新气象,趁着现在新的一年开始项目的事情还不是非常繁忙的时候,多整点下酒菜.这不实战类型的博客记录又开始了!当然实战类型的博客 ...
- 【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )
文章目录 一.环境准备 二.创建新分支应用 dev2 提交 三.git cherry-pick 冲突处理 一.环境准备 git cherry-pick 命令的作用是 将指定的 一个或若干个 提交记录 ...
- git 合并冲突_GIT提交记录和Revert commit过程分析
一.根据GIT提交记录查看提交过程 先做个git分支的背景介绍 图1 步骤说明 1⃣️ 项目A 默认分支是 master 2⃣️ 基于master分支创建 f1.f2.test分支 3⃣️ f1 发起 ...
- 导入另一个 Git库到现有的Git库并保留提交记录
提取出的主要步骤如下: 1 切换到要合并到的仓库 2 git remote add 仓库名 被合并仓库路径 3 git fetch --all 4 git merge 仓库名/被合并仓库想合并的分支 ...
- Git查看具体代码提交记录
由于时间过长,忘记了代码具体提交的作者是谁,已经该次的提交id,所以需要查询提交记录. git blame && git show 查看某一行代码的修改历史 先查看某行代码由谁写的,在 ...
- git删除远程分支提交记录(reset回去然后强推)
项目中遇到这么一个问题,git上创建了一个新项目,并且push2条修改到远程分支:但是发现注释是有问题的,想修改:其实这时候想直接删除项目重新创建,但是owner不是我,没有权限,所以这里通过git删 ...
最新文章
- 专访 | 商汤HPC负责人刘文志(风辰):未来战略的两大方向及招人的4个标准
- java web编码详解_java web 开发 编码问题详解
- 给大家分享微信小说域名防封最新的解决方案
- mysql core 文件_MySQL未能加载文件或程序集“Ubiety.Dns.Core”或它的某一个依赖项 问题的解决...
- C# SharpMap 学习总结
- 计算机视觉与模式识别国际期刊整理
- 如何在CRM WebClient UI里使用HANA Live Report
- 29. ExtJs - Struts2 整合(1) - 登录页面
- 开发技术--设计模式
- make pycaffe 报错:“fatal error: numpy/arrayobject.h: No such file or directory” 解决方案
- ROS笔记(8) 服务通信
- 【Android应用开发】 推送原理解析 极光推送使用详解 (零基础精通推送)
- 使用dom和jaxen实现一个增删改查的功能;
- java调试查看调用堆栈_关于调试:如何阅读和理解java堆栈跟踪?
- 用lex和yacc写成的一个具有解析类C语言的编译器,能够进行正确的词法、语法、语义分析并生成语法树进行可视化以及中间码。
- 爬取雪球网的股票信息评论
- Delphi 人民币大小写转换
- Linux中删除文件,磁盘空间未释放问题追踪
- 古罗马帝国莱茵河-多瑙河防线之谜
- php 生成ics文件