如果想出发,就不要等到明天!
全部博文(317)
分类: 项目管理
2013-01-27 20:49:53
1,初始状态
touch newFile.txt echo "tag 1 init" > new-commit.txt echo "tag 1 hello" >> new-commit.txt echo "tag 1 fini" >> new-commit.txt git add new-commit.txt git commit -m "for reset test tag 1 init and fini" git log --oneline git log --graph --oneline git status -s
2,初始化修改状态
echo "tag 2 init" >> new-commit.txt git add new-commit.txt echo "tag 2 hello" >> new-commit.txt git status -s
3,查看git状态
git diff git diff HEAD git diff --cached
4,查看引用指针 HEAD 与 master 的引用变更log
git reflog show git reflog show HEAD git reflog show master
5,git软重置
git reflog show master git reflog show master | head -2 git reflog show master | tail -2
git status
git reset --mixed master@{1} git diff git diff HEAD git diff --cached
6,git混合重置(default重置)
git status -s git reflog show master git reset --mixed master@{2} git diff git diff HEAD git diff --cached git status -s git reflog show master
7,git硬重置
git status -s git reflog show master git reset --hard master@{2} cat new-commit.txt git status -s git diff git diff HEAD git diff --cached
cat new-commit.txt git add new-commit.txt git status -s echo "tag 2 fini" >> new-commit.txt git status -s git diff
git diff HEAD git diff --cached
cat new-commit.txt git status -s git reflog show master git reset --hard master@{2} git reflog show master git status -s git diff git diff HEAD git diff --cached ls
总结:
1,soft重置,只改变引用指针的指向,缓冲区、工作区均不改变。
2,mixed重置,改变引用指针的指向,并且用重置后的指针指向覆盖缓冲区,但不改变工作区。
3,hard重置,改变引用指针的指向,并且用重置后的引用指向覆盖缓冲区与工作区,工作区、缓冲区所有已经被跟踪的文件都会被覆盖,没有被跟中的文件则不受影响。