Skip to content

Commit 1f03c1b

Browse files
committed
update git cheetsheet
1 parent a1d0da8 commit 1f03c1b

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

docs/posts/2019/2019-06-19-git-cheat-sheet.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ categories:
66
comments: true
77
date:
88
created: 2019-06-19
9-
updated: 2024-11-24
9+
updated: 2025-05-18
1010
description: Some personal often forgotten git commands.
1111
---
1212

@@ -22,14 +22,14 @@ User level alias
2222

2323
Edit `~/.gitconfig`
2424

25-
```ini
25+
```bash
2626
git config --global alias.amend commit --amend -C HEAD
2727
git config --global alias.st status
28-
git config --global alias.lga log --graph --decorate --oneline --all
2928
git config --global alias.co checkout
3029
git config --global alias.last log -1 HEAD
3130
git config --global alias.ci commit
3231
git config --global alias.unstage reset HEAD
32+
git config --global alias.lga log --graph --decorate --oneline --all
3333
git config --global alias.ll "log --graph --all --pretty=format:'%C(auto)%h%Creset %an: git config --global %s - %Creset %C(auto)%d%Creset %C(bold black)(%cr)%Creset %C(bold git config --global black)(%ci)%Creset' --no-abbrev-commit"
3434
git config --global alias.sh show
3535
git config --global alias.df diff
@@ -88,12 +88,12 @@ git checkout <filename or wildcard>
8888

8989
# discard changes to all files in working directory
9090
git checkout .
91+
9192
# or
9293
git checkout *
9394
```
9495

9596
!!! note
96-
9797
Untracked files cannot be discarded by checkout.
9898

9999
### Discard last commit (completely remove)
@@ -104,7 +104,6 @@ git reset --hard HEAD~
104104
```
105105

106106
!!! note
107-
108107
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.
109108

110109
### Unstage from staging area
@@ -120,11 +119,9 @@ git reset
120119
```
121120

122121
!!! note
123-
124122
No more need to add `HEAD` like `git reset HEAD <file>` and `git reset HEAD` since git v1.8.2.
125123

126124
!!! warning
127-
128125
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.
129126

130127
### Undo commit to working directory
@@ -145,17 +142,12 @@ git reset HEAD~2
145142
# Undo till a special commit to working directory,
146143
# the special commit and every commits before are still committed.
147144
git reset <commit number>
148-
149-
<!-- more -->
150-
151145
```
152146

153147
!!! 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?
156149

157150
!!! note
158-
159151
`git reset HEAD~1 <file>` will create a delete file index in staging area. Normally we don't need this command.
160152

161153
### Undo commit to staging area

0 commit comments

Comments
 (0)