Git rebase 使用记录

当你想把git 的多次提交记录合并为一次时,可以使用git rebase.
1、先查历史提交记录

 git log --pretty=format:'%h: %cd %s' --graph
* f2bb0dd: Wed Feb 8 11:14:44 2023 +0800 add reflector
* 7421ce5: Tue Feb 7 00:01:45 2023 +0800 add list watch
* b4c80af: Mon Jan 30 23:21:51 2023 +0800 add first

2、git rebase -i

 git rebase -i b4c80af   
为前开后闭区间,如想合并上面前两次的提交记录,需要以第三行的为基础

3、执行后进入如下:顺序与git log 相反

pick 7421ce5  add list watch
pick f2bb0dd   add reflector
# Rebase b4c80af..6fd7c96 onto b4c80af (1 command)
#
# 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.

4、如想合并这两次的提交为1次,可以修改hash值前的命令:

pick 7421ce5  add list watch
s    f2bb0dd   add reflector

4、 按 I 修改 ,ESC退出, :wq保存

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

推荐阅读更多精彩内容

  • # 有时候需要突然修改 .gitignore 文件,随后要立即生效 git rm -r --cached . #清...
    呵呵哈哈007阅读 81评论 0 0
  • 用文字记录生活,让思考成为习惯。近三个月的居家生活,使学生各方面发生了很大变化。学习、卫生、礼貌……很多孩子失去了...
    雨朵的笑脸阅读 59评论 0 0
  • 一直一直一直说自己喜欢写字。 就停留说里面。 写字,有在纸上写出好看的字的意思,也有用各种介质记录出各种内容的文字...
    清夢ivy阅读 103评论 0 1
  • 你好,我是邹小强,今天是一个值得庆祝的日子,因为在你用心坚持、不懈努力之下,终于迈过了100天达成人生愿望的终点线...
    萧瑟归去阅读 131评论 0 0
  • 明天才过生日,昨天就跟那爷俩说我的生日愿望是接下去的三天不干活,哈哈。娃爹跟娃说“我俩一人做两顿饭就够了”,我:“...
    燕归来2021阅读 710评论 17 6