git squash commits
  7Gc8Ums86Dem 2023年11月01日 98 0

git squash commits

key words: git squash 删除 压缩 commit 提交

起因

在做新功能测试的时候在开发分支(branch dev)上创建了一个新的分支(branch dev_experiment),在dev_experiment中做了很多尝试了,做了较多的提交,有些提交是中间过程,commit message也写的比较草率,不适合并入remote repo中,所以需要删除一些commit信息。
但是commit是不能删除的,只能压缩(squash)也就是,将多个commits合并成一个commit,这样提交记录就比较干净了。

用法

git rebase -i commit_hash^

NOTE: commit_hash^中的^用于指示是从该commit到HEAD

然后弹出编辑界面,如下。

pick 9ca62a2 commit_msg_xxxxxxxx
pick da462a1 commit_msg_yyyyyyyy
...
pick da462a1 commit_msg_zzzzzzzz

# 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.

比如说我想将9ca62a2da462a1合并,那就要将pick da462a1 commit_msg_yyyyyyyy改成squash da462a1 commit_msg_yyyyyyyy.
NOTE: 都是向上合并的# s, squash <commit> = use commit, but meld into previous commit

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  o1ZcTI9mJsxK   2024年04月15日   70   0   0 代码与软件发布
  bWqO7ATbLQET   2024年02月27日   53   0   0 代码与软件发布
7Gc8Ums86Dem
作者其他文章 更多