git 重写历史

  • 重写最后一次提交的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

 

 
 
posted @ 2014-12-25 11:06  鍒樻爧  阅读(521)  评论(0编辑  收藏  举报