美文网首页Git
Git系列6:Git 重写历史提交

Git系列6:Git 重写历史提交

作者: XBruce | 来源:发表于2020-01-02 14:16 被阅读0次

    会生成新的SHA-1
    Interactive rebase:


    image.png

    Amend 提交,仅仅修改commit message.

    $ touch fileC.txt
    
    $ git add fileC.txt
    
    $ git commit -m 'ad fileC.txt'
    [detached HEAD a1440ba] ad fileC.txt
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 fileC.txt
    
    $ git log --oneline -1
    a1440ba (HEAD) ad fileC.txt
    
    $ git commit --amend -m 'add fileC.txt'
    [detached HEAD 87d37b2] add fileC.txt
     Date: Thu Jan 2 14:02:06 2020 +0800
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 fileC.txt
    
    $ git log --oneline -1
    87d37b2 (HEAD) add fileC.txt
    

    修改文件

    $ git log --oneline -1
    893e912 (HEAD -> master, origin/master) add fileC.txt
    
    $ echo 'some text' > fileC.txt
    
    $ git add fileC.txt
    warning: LF will be replaced by CRLF in fileC.txt.
    The file will have its original line endings in your working directory.
    
    $ git commit --amend --no-edit
    [master cc04d1e] add fileC.txt
     Date: Thu Jan 2 14:08:59 2020 +0800
     1 file changed, 1 insertion(+)
     create mode 100644 fileC.txt
    
    $ git log --oneline -1
    cc04d1e (HEAD -> master) add fileC.txt#SHA-1已经改变
    
    image.png

    相关文章

      网友评论

        本文标题:Git系列6:Git 重写历史提交

        本文链接:https://www.haomeiwen.com/subject/bjxooctx.html