diff --git a/basic/index.html b/basic/index.html index effba37..827bab7 100644 --- a/basic/index.html +++ b/basic/index.html @@ -597,10 +597,10 @@ Further paragraphs come after blank lines.
In this case, we can use it to unstage something that you have +
In the first case, we can use it to unstage something that you have accidentally staged. Let's say that you have modified two files and want to record them into two different commits. You should stage and commit one, then stage and commit the other. If you accidentally stage both of @@ -682,11 +687,83 @@ M hello.rb # +
When you run git reset
without specifying a flag
+ it defaults to --mixed
. The other options are
+ --soft
and --hard
.
The first thing git reset
does is undo the last
+ commit and put the files back onto the stage. If you include the
+ --soft
flag this is where it stops. For example,
+ if you run git reset --soft HEAD~
(the parent of the
+ HEAD) the last commit will be undone and the files touched
+ will be back on the stage again.
+$ git status -s +M hello.rb +$ git commit -am 'hello with a flower' +[master 5857ac1] hello with a flower + 1 files changed, 3 insertions(+), 1 deletions(-) +$ git status +# On branch master +nothing to commit (working directory clean) +$ git reset --soft HEAD~ +$ git status -s +M hello.rb ++ +
This is basically doing the same thing as
+ git commit --amend
, allowing you to do more work
+ before you roll in the file changes into the same commit.
The third option is to go --hard
and make your working
+ directory look like the index, unstage files and undo the last commit.
+ This is the most dangerous option and not working directory safe. Any
+ changes not in the index or have not been commited will be lost.
+$ git status +# On branch master +# Changes to be committed: +# (use "git reset HEAD+ +..." to unstage) +# +# modified: README +# +# Changes not staged for commit: +# (use "git add ..." to update what will be committed) +# (use "git checkout -- ..." to discard changes in working directory) +# +# modified: README +# +$ git reset --hard HEAD +HEAD is now at 5857ac1 hello with a flower +$ git status +# On branch master +nothing to commit (working directory clean) +
In the above example, while we had both changes ready to commit and
+ ready to stage, a git reset --hard
wiped them out.
+ On top of that, the last commit has been undone.
You can replace HEAD
with a commit SHA-1 or another
+ parent reference to reset to that specific point.
In a nutshell,
- you run git reset HEAD
to unstage files that you previously
- ran git add
on and wish to not include in the next commit
- snapshot
git reset HEAD
to undo the last commit, unstage
+ files that you previously ran git add
on and wish to not
+ include in the next commit snapshot