git进阶 之 reflog
2020-06-03 本文已影响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 is all about commits: you stage commits, create commits, view old commits, and transfer commits between repositories using many different Git commands
- git-log - Show commit logs
引用
- git三大常见引用: HEAD(指向当前分支) / Branch / Tag
- 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
- git-reflog - Record when the tips of branches and other references were updated in the local repository
场景
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