# Rebase 3751363..9f85bd4 onto 3751363 # # 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
上面的两行是执行的指令, 下面的注释是各种指令简单的介绍。
p, pick = use commit s, squash = use commit, but meld into previous commit
# This is a combination of 2 commits. # The first commit's message is: test2 # This is the 2nd commit message: test3 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Mon Nov 3 15:40:11 2014 +0800 # # rebase in progress; onto 3751363 # You are currently editing a commit while rebasing branch 'master' on '3751363'. # # Changes to be committed: # modified: index.js
将注释改成自己想改的,像我在这里注释掉了 test2 和 test 3, 加了 test 。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
test
# This is a combination of 2 commits. # The first commit's message is: # test2 # This is the 2nd commit message: # test 3 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Mon Nov 3 15:40:11 2014 +0800 # # rebase in progress; onto 3751363 # You are currently editing a commit while rebasing branch 'master' on '3751363'. # # Changes to be committed: # modified: index.js #
接下来保存退出, 这时候再用 git log 查看当前的 commit 是否正确:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
commit 63bcb30ac082311e1116cd8a96db5ef437bda5b1 Author: minary <i@f10.com> Date: Mon Nov 315:40:112014 +0800 test commit 375136336ebef674fec77355214e65049fdb5ad8 Author: minary <i@f10.com> Date: Mon Nov 315:39:052014 +0800 test commit 890faef7ceeafe3216438355be9e5bf1282c2e33 Author: minary <i@f10.com> Date: Thu Oct 1610:56:492014 +0800 ssh commit 3b4d793b68d7bbea89e3bc290f25f299984812dc Author: minary <i@f10.com> Date: Thu Oct 1610:53:512014 +0800 first commit (END)
可以看出 test2 和 test 3 已经不见, 变成了 test 。
最后一步,将本地修改push到远程就好:
1
$ git push origin master
可能会报下面类似的错误:
1 2 3 4 5 6 7
To ssh://gitlab@gitlab.XXX.com:65422/XXX/tears.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ssh://gitlab@gitlab.XXX.com:65422/XXX/tears.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint:'git pull ...') before pushing again. hint: See the 'Note about fast-forwards'in'git push --help'for details.