@@ -597,10 +597,10 @@ <h4>
597
597
< h2 >
598
598
< span class ="docs ">
599
599
< a target ="new " href ="http://git-scm.com/docs/git-reset "> docs</ a >
600
- < a target ="new " href ="http://git-scm.com/book/ch2-4.html #Unstaging-a-Staged-File "> book</ a >
600
+ < a target ="new " href ="http://git-scm.com/book/en/Git-Basics-Undoing-Things #Unstaging-a-Staged-File "> book</ a >
601
601
</ span >
602
- < a name ="reset "> git reset HEAD </ a >
603
- < span class ="desc "> unstage changes that you have staged </ span >
602
+ < a name ="reset "> git reset</ a >
603
+ < span class ="desc "> undo changes and commits </ span >
604
604
</ h2 >
605
605
606
606
< div class ="block ">
@@ -612,7 +612,12 @@ <h2>
612
612
very useful.
613
613
</ p >
614
614
615
- < p > In this case, we can use it to unstage something that you have
615
+ < h4 >
616
+ git reset HEAD
617
+ < small > undo the last commit and unstage the files</ small >
618
+ </ h4 >
619
+
620
+ < p > In the first case, we can use it to unstage something that you have
616
621
accidentally staged. Let's say that you have modified two files and want
617
622
to record them into two different commits. You should stage and commit
618
623
one, then stage and commit the other. If you accidentally stage both of
@@ -682,11 +687,83 @@ <h2>
682
687
#
683
688
</ pre >
684
689
690
+ < p > When you run < code > git reset</ code > without specifying a flag
691
+ it defaults to < code > --mixed</ code > . The other options are
692
+ < code > --soft</ code > and < code > --hard</ code > .</ p >
693
+
694
+ < h4 >
695
+ git reset --soft
696
+ < small > undo the last commit</ small >
697
+ </ h4 >
698
+
699
+ < p > The first thing < code > git reset</ code > does is undo the last
700
+ commit and put the files back onto the stage. If you include the
701
+ < code > --soft</ code > flag this is where it stops. For example,
702
+ if you run < code > git reset --soft HEAD~</ code > (the parent of the
703
+ HEAD) the last commit will be undone and the files touched
704
+ will be back on the stage again.</ p >
705
+
706
+ < pre >
707
+ < b > $ git status -s</ b >
708
+ < span class ="green "> M</ span > hello.rb
709
+ < b > $ git commit -am 'hello with a flower'</ b >
710
+ [master 5857ac1] hello with a flower
711
+ 1 files changed, 3 insertions(+), 1 deletions(-)
712
+ < b > $ git status</ b >
713
+ # On branch master
714
+ nothing to commit (working directory clean)
715
+ < b > $ git reset --soft HEAD~</ b >
716
+ < b > $ git status -s</ b >
717
+ < span class ="green "> M</ span > hello.rb
718
+ </ pre >
719
+
720
+ < p > This is basically doing the same thing as
721
+ < code > git commit --amend</ code > , allowing you to do more work
722
+ before you roll in the file changes into the same commit.</ p >
723
+
724
+ < h4 >
725
+ git reset --hard
726
+ < small > undo the last commit, unstage files AND undo any changes in the working directory</ small >
727
+ </ h4 >
728
+
729
+ < p > The third option is to go < code > --hard</ code > and make your working
730
+ directory look like the index, unstage files and undo the last commit.
731
+ This is the most dangerous option and not working directory safe. Any
732
+ changes not in the index or have not been commited will be lost.</ p >
733
+
734
+ < pre >
735
+ < b > $ git status</ b >
736
+ # On branch master
737
+ # Changes to be committed:
738
+ # (use "git reset HEAD < file > ..." to unstage)
739
+ #
740
+ # < span class ="green "> modified: README</ span >
741
+ #
742
+ # Changes not staged for commit:
743
+ # (use "git add < file > ..." to update what will be committed)
744
+ # (use "git checkout -- < file > ..." to discard changes in working directory)
745
+ #
746
+ # < span class ="red "> modified: README</ span >
747
+ #
748
+ < b > $ git reset --hard HEAD</ b >
749
+ HEAD is now at 5857ac1 hello with a flower
750
+ < b > $ git status</ b >
751
+ # On branch master
752
+ nothing to commit (working directory clean)
753
+ </ pre >
754
+
755
+ < p > In the above example, while we had both changes ready to commit and
756
+ ready to stage, a < code > git reset --hard</ code > wiped them out.
757
+ On top of that, the last commit has been undone.</ p >
758
+
759
+ < p > You can replace < code > HEAD</ code > with a commit SHA-1 or another
760
+ parent reference to reset to that specific point.</ p >
761
+
685
762
< p class ="nutshell ">
686
763
< strong > In a nutshell</ strong > ,
687
- you run < code > git reset HEAD</ code > to unstage files that you previously
688
- ran < code > git add</ code > on and wish to not include in the next commit
689
- snapshot</ p >
764
+ you run < code > git reset HEAD</ code > to undo the last commit, unstage
765
+ files that you previously ran < code > git add</ code > on and wish to not
766
+ include in the next commit snapshot</ p >
690
767
691
768
</ div >
692
769
</ div >
0 commit comments