You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -88,12 +88,12 @@ git checkout <filename or wildcard>
88
88
89
89
# discard changes to all files in working directory
90
90
git checkout .
91
+
91
92
# or
92
93
git checkout *
93
94
```
94
95
95
96
!!! note
96
-
97
97
Untracked files cannot be discarded by checkout.
98
98
99
99
### Discard last commit (completely remove)
@@ -104,7 +104,6 @@ git reset --hard HEAD~
104
104
```
105
105
106
106
!!! note
107
-
108
107
We can recover the commit discarded by `--hard` with the `git cherry-pick [commit number]` if we displayed or saved it before. Whatever you can also use `git reflog` to get the commit number too.
109
108
110
109
### Unstage from staging area
@@ -120,11 +119,9 @@ git reset
120
119
```
121
120
122
121
!!! note
123
-
124
122
No more need to add `HEAD` like `git reset HEAD <file>` and `git reset HEAD` since git v1.8.2.
125
123
126
124
!!! warning
127
-
128
125
Do not use `git rm --cached <filename>` to unstage, it works only for newly created file to remove them from the staging area. But if you specify a existing file, it will delete it from cache, even if it is not staged.
129
126
130
127
### Undo commit to working directory
@@ -145,17 +142,12 @@ git reset HEAD~2
145
142
# Undo till a special commit to working directory,
146
143
# the special commit and every commits before are still committed.
147
144
git reset <commit number>
148
-
149
-
<!-- more -->
150
-
151
145
```
152
146
153
147
!!! note
154
-
155
-
`git reset HEAD` will do nothing, as the HEAD is already at the last commit.
148
+
`git reset HEAD` will do nothing, as the HEAD is already at the last commit.What?
156
149
157
150
!!! note
158
-
159
151
`git reset HEAD~1 <file>` will create a delete file index in staging area. Normally we don't need this command.
0 commit comments