$ git checkout feature
$ git rebase develop
解决冲突
$ git add .
$ git rebase --continue
$ git push -f
查看提交历史:
$ git log
rebase 最近的5次提交,-i代表交互式interactive:
git rebase -i HEAD~5
ChudeMac-mini:ODI808 ChuGuimin$ git rebase -i HEAD~5
pick d72e6e2 common commit
pick da7fd0a common commit
pick d29b536 Update .gitignore
pick 7b30cd2 common commit
pick 7096558 common commit
# Rebase 5ddeda6..7096558 onto 5ddeda6 (5 commands)
#
# 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
# d, drop = remove commit
#
# 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
修改第2-5行的第一个单词pick -> squash:
ChudeMac-mini:ODI808 ChuGuimin$ git rebase -i HEAD~5
pick d72e6e2 common commit
squash da7fd0a common commit
squash d29b536 Update .gitignore
squash 7b30cd2 common commit
squash 7096558 common commit
# Rebase 5ddeda6..7096558 onto 5ddeda6 (5 commands)
#
# 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
# d, drop = remove commit
#
# 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
如果没有冲突,会出现如下:
# This is a combination of 5 commits.
# The first commit’s message is:
这里是注释
# The 2nd commit’s message is:
这里是注释
# The 3rd commit’s message is:
这里是注释
# The 4th commit’s message is:
这里是注释
# The 5th commit’s message is:
这里是注释
# Please enter the commit message for your changes. Lines starting
# with ‘#’ will be ignored, and an empty message aborts the commit.
如果有冲突,需要修改,修改的时候要注意,保留最新的历史,不然我们的修改就丢弃了。修改以后要记得敲下面的命令:
git add .
git rebase --continue
如果你想放弃这次压缩的话,执行以下命令:
git rebase --abort
最后提交到远程仓库:
git push -f
回滚到某个commit:
回退命令:
git reset --hard HEAD^ 回退到上个版本
git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前
git reset --hard commit_id 退到/进到 指定commit的sha码
强推到远程:
git push origin HEAD --force