码迷,mamicode.com
首页 > 其他好文 > 详细

git reset的用法

时间:2018-08-18 10:29:27      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:zed   repos   nbsp   not   res   假设   mode   osi   cond   

git reset三个选项

  --mix,--hard,--soft

 

数据

  针对每个选项都是操作这个文件。

[root@centos demo]# git init
Initialized empty Git repository in /root/demo/.git/
[root@centos demo]# echo one >> a.txt
[root@centos demo]# git add a.txt
[root@centos demo]# git commit -m "first commit"
[master (root-commit) b7ee3a2] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[root@centos demo]# echo two >> a.txt
[root@centos demo]# git commit -am "second commit"
[master 92ae9c4] second commit
 1 file changed, 1 insertion(+)
[root@centos demo]# echo three >> a.txt
[root@centos demo]# git commit -am "third commit"
[master 0985eec] third commit
 1 file changed, 1 insertion(+)
[root@centos demo]# echo four >> a.txt
[root@centos demo]# git commit -am "four commit"
[master 5bd480c] four commit
 1 file changed, 1 insertion(+)
[root@centos demo]# git show-branch --more=4    #查看四次提交记录
[master] four commit
[master^] third commit
[master~2] second commit
[master~3] first commit

  

git reset --mix

  在省略reset选项的时候,默认的就是使用--mix

[root@centos demo]# git reset HEAD~2
Unstaged changes after reset:
M       a.txt
[root@centos demo]# 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:   a.txt

no changes added to commit (use "git add" and/or "git commit -a")
[root@centos demo]# cat a.txt
one
two
three
four
[root@centos demo]#  git diff
diff --git a/a.txt b/a.txt
index 69f75fc..a4c0ca1 100644
--- a/a.txt
+++ b/a.txt
@@ -1,2 +1,4 @@
 one
 two
+three
+four

  从运行结果可以看出来,--mix有以下特点:

  技术分享图片

  假设使用reset命令从版本D回到版本B,那么HEAD就会指向B。同时,从版本B到版本D之间做的文件修改并不会丢失,会保留版本D相对于B的diff。

 

git reset --hard

  

git reset的用法

标签:zed   repos   nbsp   not   res   假设   mode   osi   cond   

原文地址:https://www.cnblogs.com/-beyond/p/9495971.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!