压缩提交记录
2024/3/4 23:02:20
本文主要是介绍压缩提交记录,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
运用场景
在没有推送本地修改到共用分支之前,可以通过变基操作整理提交历史。
执行步骤
执行 git log,列出所有的提交:
$ git checkout main $ git log commit ff3490694a2168a94abc0188fe35cdd102d3c7fc (HEAD -> main, origin/main, origin/iss53, iss53) Author: zhanglianwei <zhanglianwei@meituan.com> Date: Wed Feb 21 16:09:29 2024 +0800 第二次修改iss53 commit b0a67cb1bbd16e8a812516dad50b129961f483f7 (iss52) Author: zhanglianwei <zhanglianwei@meituan.com> Date: Wed Feb 21 16:02:42 2024 +0800 修改iss52 commit 9f5bfba20b0448961111fe1cc621187b461284c4 Author: zhanglianwei <zhanglianwei@meituan.com> Date: Wed Feb 21 16:00:55 2024 +0800 修改hotfix commit ca5ebf0f7e0438c514b9039594e86b6bc1ef64e2 Author: zhanglianwei <zhanglianwei@meituan.com> Date: Tue Jan 30 16:24:42 2024 +0800 :
通过给 git rebase
增加 --interactive
( 简写为 -i
)选项来交互式地运行变基,可以将一连串提交压缩成一个单独的提交。
$ git rebase -i HEAD~3 # 也可以使用哈希值 git rebase -i ca5ebf0 pick 9f5bfba 修改hotfix pick b0a67cb 修改iss52 pick ff34906 第二次修改iss53 # Rebase ca5ebf0..ff34906 onto ca5ebf0 (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 [-C | -c] <commit> = like "squash" but keep only the previous # commit's log message, unless -C is used, in which case # keep only this commit's message; -c is same as -C but # opens the editor # 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>] "~/git-practise/.git/rebase-merge/git-rebase-todo" 34L, 1566B
如果想要这三次提交变为一个提交,可以这样修改上面的内容:
pick 9f5bfba 修改hotfix squash b0a67cb 修改iss52 # 简写 s 也可以 squash ff34906 第二次修改iss53 # 简写 s 也可以 当保存并退出编辑器时,会展示出三次提交信息: # This is a combination of 3 commits. # This is the 1st commit message: 修改iss52 # This is the commit message #2: 修改iss53 # This is the commit message #3: 第二次修改iss53 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Wed Feb 21 16:02:42 2024 +0800 # # interactive rebase in progress; onto 9f5bfba # Last commands done (3 commands done): # squash 3f9efe3 修改iss53 "~/git-practise/.git/COMMIT_EDITMSG" 28L, 669B
合并三次提交信息:
# This is a combination of 3 commits. # This is the 1st commit message: 修改iss52、iss53 # This is the commit message #2: # This is the commit message #3:
保存之后,再次执行 git log
,三次提交变为一个提交。
$ git log commit 877ae9ea21b69947dec3c2fce588c1da7e955ee6 (HEAD -> main) Author: zhanglianwei <zhanglianwei@meituan.com> Date: Wed Feb 21 16:00:55 2024 +0800 修改iss52、iss53 commit ca5ebf0f7e0438c514b9039594e86b6bc1ef64e2 Author: zhanglianwei <zhanglianwei@meituan.com> Date: Tue Jan 30 16:24:42 2024 +0800 first commit
最后,通过 git push -f
强制推送至远程仓库即可。
这篇关于压缩提交记录的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?