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:
- HEAD
- Commit2
- Commit1
Say we want to modify "Commit2":
- Run rebase, say commit id of Commit2 is
6fb592
Be careful with the ^
git rebase -i 6fb592^
- Edit (Pay attentation, edit the one you want to modify)
In the new window, edit the value of $idOfCommit2, frompick
toedit
. - Make changes to that commit
- git add
git add -u // If there is no new file within this change
- 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"
- Continue rebase
git rebase --continue
- Check
Check if the new commits are as expected - git push
git push -f // Since the git commit history is changed, need -f