美文网首页
git进阶 之 reflog

git进阶 之 reflog

作者: 诺之林 | 来源:发表于2020-06-03 10:00 被阅读0次

    示例

    mkdir git-demo && cd git-demo
    
    git init
    
    echo 0 > test
    
    git add .
    
    git commit -am "init 0" 
    
    echo "1" >> test
    
    git commit -am "add 1"
    
    git checkout -b feature
    
    git log --oneline
    # cb41bee (HEAD -> master) add 1
    # f9ca73f init 0
    
    cat .git/refs/heads/master
    # cb41beed05d68b8792d09b7125caad50acc95c7a
    
    cat .git/HEAD
    # ref: refs/heads/feature
    

    提交

    • git三大对象类型: 数据对象(Blob Object) / 树对象(Tree Object) / 提交对象(Commit Object)

    git进阶 之 object

    • git is all about commits: you stage commits, create commits, view old commits, and transfer commits between repositories using many different Git commands

    Atlassian Refs and the Reflog

    • git-log - Show commit logs

    Git Documents git-log

    引用

    • git三大常见引用: HEAD(指向当前分支) / Branch / Tag

    git进阶 之 reference

    • A ref is an indirect way of referring to a commit. You can think of it as a user-friendly alias for a commit hash

    Atlassian Refs and the Reflog

    • git-reflog - Record when the tips of branches and other references were updated in the local repository

    Git Documents git-reflog

    场景

    git reset --hard HEAD^
    # HEAD is now at f9ca73f init 0
    
    git log --oneline
    # f9ca73f (HEAD -> master) init 0
    
    git reflog
    # f9ca73f (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
    # cb41bee HEAD@{1}: commit: add 1
    # f9ca73f (HEAD -> master) HEAD@{2}: commit (initial): init 0
    
    git reset --hard HEAD@{1}
    # HEAD is now at cb41bee add 1
    
    git log --oneline
    # cb41bee (HEAD -> master) add 1
    # f9ca73f init 0
    

    参考

    相关文章

      网友评论

          本文标题:git进阶 之 reflog

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