2019-03-07 Git高级管理

2019-03-09  本文已影响0人  阿丧小威

1. git checkout命令

git checkout hotfix after checkout

HEAD由Master转到Hotfix上了

git checkout HEAD~2

后面加了HEAD~2,提交后,HEAD指向了该分支前两次提交的那里

2. checkout

checkout file

示例:

[root@localhost test]# vi index.html 
<h1>hello world</h1>
test checkout file    ---新添加的修改项
:wq
[root@localhost test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   index.html    ---提示已修改

no changes added to commit (use "git add" and/or "git commit -a")
[root@localhost test]# git checkout -- index.html     ---撤销文件
[root@localhost test]# git status
On branch master
nothing to commit, working directory clean    ---变回没修改的状态了

3. git reset

git reset HEAD~2 git reset HEAD~2

HEAD~2往前撤了两次,后面的两个不见了

reset参数影响

--soft只回撤本地版本库,--mixed只回撤暂存区和本地版本库,--hard全部都清了。
示例:

[root@localhost test]# git status
On branch master
nothing to commit, working directory clean
[root@localhost test]# ll
total 20-
-rw-r--r--. 1 root root  7 Mar  2 22:30 about2.html
-rw-r--r--. 1 root root  9 Mar  2 22:30 about.html
-rw-r--r--. 1 root root 21 Mar  2 23:12 index.html
-rw-r--r--. 1 root root  5 Mar  2 20:38 news.html
-rw-r--r--. 1 root root 22 Mar  2 20:43 test.html
[root@localhost test]# vi index.html 
<h1>hello world</h1>
2333333    ---新添加的
:wq
[root@localhost test]# vi news.html 
news
abbbbbb    ---新添加内容
:wq
[root@localhost test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   index.html
    modified:   news.html

no changes added to commit (use "git add" and/or "git commit -a")
[root@localhost test]# git add news.html 
[root@localhost test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)    ---缓存区

    modified:   news.html

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)    ---工作目录

    modified:   index.html
[root@localhost test]# git log
commit 96c9ee3183d8589922448da51a66554037f4c76b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 22:16:16 2019 +0800

    about2

commit 06c81edf9d8db4ab95c1558f8a551ac81de5a659
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 21:40:40 2019 +0800

    about

commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# git reset --hard 8ce4e28510f0bdf1153c064e507b11e2b2052744    ---缓存区和工作目录都回滚到news那里
HEAD is now at 8ce4e28 news
[root@localhost test]# git status
On branch master
nothing to commit, working directory clean    ---工作目录和暂存区都被清空了
[root@localhost test]# git log    ---只剩下news和news之前的提交了
commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit

4. 文件层操作

reset file

reset会把文件拉到暂存区里

使用场景

5. reflog

上一篇 下一篇

猜你喜欢

热点阅读