Git modify history commit

REM: Be careful if this is amaster branch, or a branch which multiple people are working on

Say there are multiple commits:

  1. HEAD
  2. Commit2
  3. Commit1

Say we want to modify "Commit2":

  1. Run rebase, say commit id of Commit2 is 6fb592
    Be careful with the ^
git rebase -i 6fb592^
  1. Edit (Pay attentation, edit the one you want to modify)
    In the new window, edit the value of $idOfCommit2, from pick to edit.
  2. Make changes to that commit
  3. git add
git add -u // If there is no new file within this change
  1. git commit
git commit --amend --no-edit // If there is no need to update the commit message

OR

git commit --amend -m "Some now commit message"
  1. Continue rebase
git rebase --continue
  1. Check
    Check if the new commits are as expected
  2. git push
git push -f // Since the git commit history is changed, need -f
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容