$ 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行的第一個(gè)單詞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
如果沒(méi)有沖突杀捻,會(huì)出現(xiàn)如下:
# 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.
如果有沖突,需要修改耙替,修改的時(shí)候要注意涨享,保留最新的歷史缸废,不然我們的修改就丟棄了吟秩。修改以后要記得敲下面的命令:
git add .
git rebase --continue
如果你想放棄這次壓縮的話咱扣,執(zhí)行以下命令:
git rebase --abort
最后提交到遠(yuǎn)程倉(cāng)庫(kù):
git push -f
回滾到某個(gè)commit:
回退命令:
git reset --hard HEAD^ 回退到上個(gè)版本
git reset --hard HEAD~3 回退到前3次提交之前,以此類(lèi)推涵防,回退到n次提交之前
git reset --hard commit_id 退到/進(jìn)到 指定commit的sha碼
強(qiáng)推到遠(yuǎn)程:
git push origin HEAD --force