美文网首页Git
Git modify history commit

Git modify history commit

作者: JaedenKil | 来源:发表于2021-06-30 19:12 被阅读0次
    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
    

    相关文章

      网友评论

        本文标题:Git modify history commit

        本文链接:https://www.haomeiwen.com/subject/gkarultx.html