git rebase

rebase.png
$ 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  

如果你想放棄這次壓縮的話,執(zhí)行以下命令:

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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容