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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容