Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1825845
  • 博文数量: 317
  • 博客积分: 1557
  • 博客等级: 上尉
  • 技术积分: 1208
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-26 23:38
个人简介

如果想出发,就不要等到明天!

文章分类

全部博文(317)

文章存档

2016年(1)

2015年(41)

2014年(152)

2013年(114)

2012年(4)

2011年(1)

2009年(4)

分类: 项目管理

2013-01-28 23:09:44

1,git 库状态:

ll
cat newFile.txt
cat welcome.txt
git status -s
git diff
git diff HEAD
git diff --cached
git log --oneline
git reflog
git reflog -l
git reflog show HEAD
git reflog show master

2,分离头指针状态与恢复:

cat .git/HEAD
git branch -v
git checkout e5bbef2^
cat .git/HEAD
git reflog -l
git rev-parse HEAD master
touch detached-commit.txt
git add detached-commit.txt
git status
git commit -m "commit in detached HEAD mode."
cat .git/HEAD
git log --graph --oneline
git reflog
git diff
git diff HEAD
git diff --cached
git status
ll
git checkout master
git .git/HEAD
ll
git log --graph --oneline
git show 4c2ec75

3,挽救分离头指针状态的提交损失:

ll
git status -s
git branch -v
git merge 4c2ec75
ll
git status -s
git branch -v
git log --graph --oneline
git reflog show master
git reflog show HEAD
git cat-file -p HEAD

4, git checkout 的几种用法

4.1,初始化git库


echo "newFile a1" >> newFile_a1.txt
git add newFile_a1.txt
git commit -m "newFile a1 is added"
echo "newFile a2" >> newFile_a2.txt
git add newFile_a2.txt
git commit -m "newFile a2 is added"
echo "newFile a3" >> newFile_a3.txt
git add newFile_a3.txt
git commit -m "newFile a3 is added"
git log --oneline --graph

4.2,git checkout 与 git checkout HEAD

汇总显示工作区、暂存区与HEAD的差异

git status -s
echo "Hello a3." >> newFile_a3.txt
git add newFile_a3.txt
git status -s
echo "Nice to meet you a3." >> newFile_a3.txt
git status -s

git status -s
git checkout
git status -s
git checkout HEAD
git status -s
echo "new file a4" >> newFile_a4.txt
git add newFile_a4.txt
git status -s
git checkout
git checkout HEAD
echo "Nice to meet you a4." >> newFile_a4.txt
git status -s
git checkout
git checkout HEAD

git diff
git diff HEAD

git diff --cached


4.3 git checkout [commit] [--]

从指定commit中checkout指定文件覆盖到工作区,但不影响暂存区、HEAD、master指向。

若缺省commit,则默认从暂存区checkout指定文件的上一次add的版本覆盖到工作区,同样不影响暂存区、HEAD、master指向。

git log --oneline --graph
git status -s
git checkout -- newFile_a3.txt
git status -s
git checkout HEAD -- newFile_a3.txt
git status -s

缺省[commit]参数的 newFile_a3.txt 的 checkout ,从暂存区覆盖到工作区。

指定[commit]参数为 HEAD 的 newFile_a3.txt 的 checkout ,从HEAD指向的版本覆盖暂存区、工作区。

git reflog show HEAD | head -3
git reflog show master | head -3

由此可见 此用法没有改变 HEAD 、master 的指向。

git diff
git diff HEAD
git diff --cached

4.4, "git checkout -- ." 与 "git checkout ."

把暂存区目录树checkout覆盖工作区目录树。

git status -s
cat newFile_a3.txt
echo "Hello a3." >> newFile_a3.txt
git add newFile_a3.txt
echo "Nice to meet you ." >> newFile_a3.txt
git status -s
git checkout -- .
git status -s
cat newFile_a3.txt
echo "Nice to meet you." >> newFile_a3.txt
git status -s
git checkout .
git status -s

4.5,"git checkout [branch]"

实现branch切换,更新 HEAD 指向至 branch,用 HEAD 指向更新暂存区、工作区。

git status -s
git diff --cached
echo "Nice to meet you a3." >> newFile_a3.txt
git status -s
git checkout master
git status -s

由于只有一个 master branch,所以提示我们already on 'master',并且不做任何改动。













阅读(4176) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~