原文:点击打开链接
referer url: http://stackoverflow.com/questions/5189560/how-can-i-squash-my-last-x-commits-together-using-git
FOR EXAMPLE:
I have 3 commits in history:
commit 1: #3333 zzzzzz
commit 2: #2222 yyyyyy
commit 3: #1111 xxxxxx
NOW, I want to squash last 2 commits
Step 1:
$ git reset --hard HEAD~2
then the output like this:
HEAD 现在位于 4cf49a1 #255 斗金绿色平台开发者列表可以按照选择拓展人员查看对应开发者列表
Step 2:
$ git merge --squash HEAD@{1}
then the output like this:
更新 4cf49a1..399379d
Fast-forward
压缩提交 -- 未更新 HEAD
Controller/0000Controller.php | 65 +++++++++++++++++++++++++
Controller/111111Controller.php | 22 ++++++++-
Model/33333.php | 78 +++++++++++++++++++++++++++++-
View/44444/5555.ctp | 10 +++-
View/4444/666666.ctp | 41 ++++++++++++++++
webroot/js/44444/xxxxx.js | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 381 insertions(+), 3 deletions(-)
create mode 100644 View/aaaa/xxx.ctp
create mode 100644 webroot/js/aaaa/bbbb.js
Step 3:
$ git commit -m "#255 aaaaaa"
OUTPUT:
[master 8f35d2d] #255 aaaaaa
6 files changed, 381 insertions(+), 3 deletions(-)
create mode 100644 View/aaaa/bbbb.ctp
create mode 100644 webroot/js/aaaa/bbbb.js
Step 4:
$ git push
OUTPUT:
To [email protected]:xxxx/bbbb.git
! [rejected] master -> master (non-fast-forward)
error: 无法推送一些引用到 '[email protected]:xxxx/bbbb.git'
提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 'git pull')。详见
提示:'git push --help' 中的 'Note about fast-forwards' 小节。
if push get errors, you need to force push:
$ git push origin +master
OUTPUT:
Counting objects: 27, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (15/15), 4.03 KiB | 0 bytes/s, done.
Total 15 (delta 9), reused 0 (delta 0)
To [email protected]:aaa/xxx.git
+ 399379d...8f35d2d master -> master (forced update)