Think before you speak, read before you think.

git 压缩提交 squash merge

by

in

分支里多次提交合并成一个提交

示例

将最近几个(number_of_commits) 提交合并成一个提交

git rebase -i HEAD~[number_of_commits]

然后进入交互式选择

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

这里先进行 commit 方面的选择,把除去第一行的都改为 squash

pick f7f3f6d changed my name a bit
squash 310154e updated README formatting and added blame
squash a5f4a0d added cat-file

然后进行 commit msg 的界面,自己写一下合并后的 commit。

分支的 push 强制提交会将本地操作生效

参考:

pro git


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *