很多时候,把本地多个Git commit合并为一个再push,有很大的优势。这个操作在Git中被称为Squash。
示例如下:
# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
git commit
参考文献
[1] https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git
网友评论