- 重写最后一次提交的commit
git commit --amend
- 修改多个历史
git rebase -i HEAD~3
命令执行后结果如下:
pick f7f3f6d changed my name a bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file # Rebase 710f0f8..a5f4a0d onto 710f0f8 # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
将你想修改的每一次提交前面的pick改为edit
edit f7f3f6d changed my name a bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file
当你保存并退出编辑器,Git会倒回至列表中的最后一次提交,然后把你送到命令行中,同时显示以下信息:
$ git rebase -i HEAD~3 Stopped at 7482e0d... updated the gemspec to hopefully work better You can amend the commit now, with git commit --amend Once you’re satisfied with your changes, run git rebase --continue
然后
$ git commit --amend $ git rebase --continue
ok一切搞定。
参照资料地址:http://git-scm.com/book/zh/ch6-4.html
时间: 2024-11-04 14:39:20