Git

Git modify history commit

2021-06-30  本文已影响0人  JaedenKil
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
上一篇下一篇

猜你喜欢

热点阅读