2020-05-08 18:48:34 +00:00
|
|
|
# Git
|
2020-02-17 17:28:12 +00:00
|
|
|
|
2020-07-07 18:11:14 +00:00
|
|
|
## Config
|
|
|
|
|
2020-06-12 20:00:31 +00:00
|
|
|
Aliases:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git config --global alias.br branch
|
|
|
|
git config --global alias.ci commit
|
2020-07-07 18:11:14 +00:00
|
|
|
git config --global alias.co checkout
|
|
|
|
git config --global alias.df diff
|
2020-06-12 20:00:31 +00:00
|
|
|
git config --global alias.st status
|
2020-08-14 09:54:50 +00:00
|
|
|
git config --global alias.sw switch
|
2020-06-12 20:00:31 +00:00
|
|
|
```
|
|
|
|
|
2020-08-20 09:41:51 +00:00
|
|
|
Use nice editor when commit:
|
2020-05-09 18:30:08 +00:00
|
|
|
|
|
|
|
```sh
|
2020-08-20 09:41:51 +00:00
|
|
|
git config --global core.editor <editor>
|
2020-05-09 18:30:08 +00:00
|
|
|
```
|
|
|
|
|
2020-07-07 18:11:14 +00:00
|
|
|
## Commands
|
|
|
|
|
2020-02-17 17:28:12 +00:00
|
|
|
Prefer rebase when pull:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git pull --rebase
|
|
|
|
```
|
|
|
|
|
|
|
|
Clean outdated branches:
|
|
|
|
|
|
|
|
```sh
|
2020-03-19 03:04:02 +00:00
|
|
|
git fetch --prune
|
2020-02-17 17:28:12 +00:00
|
|
|
```
|
|
|
|
|
2020-07-07 18:11:14 +00:00
|
|
|
Push force **safely**:
|
2020-02-17 17:28:12 +00:00
|
|
|
|
|
|
|
```sh
|
2020-03-19 03:04:02 +00:00
|
|
|
git push --force-with-lease
|
2020-02-17 17:28:12 +00:00
|
|
|
```
|
|
|
|
|
2020-03-28 15:02:25 +00:00
|
|
|
Rewrite history by changing last `x` commits :
|
2020-02-28 20:51:00 +00:00
|
|
|
|
|
|
|
```sh
|
2020-08-20 09:41:51 +00:00
|
|
|
git rebase -i HEAD~<x>
|
2020-02-28 20:51:00 +00:00
|
|
|
```
|
2020-07-10 04:18:24 +00:00
|
|
|
|
|
|
|
Squash last `x` commits to 1 commit:
|
|
|
|
|
|
|
|
```sh
|
2020-08-20 09:41:51 +00:00
|
|
|
git reset HEAD~<x>
|
2020-07-10 04:18:24 +00:00
|
|
|
git add -A
|
|
|
|
git commit
|
|
|
|
```
|
|
|
|
|
|
|
|
Cleanup unnecessary files:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git gc
|
|
|
|
```
|
2020-07-10 05:45:14 +00:00
|
|
|
|
|
|
|
Find common ancestor:
|
|
|
|
|
|
|
|
```sh
|
2020-08-20 09:41:51 +00:00
|
|
|
git merge-base <A> <B>
|
|
|
|
```
|
|
|
|
|
|
|
|
Log:
|
|
|
|
|
2020-09-28 15:30:57 +00:00
|
|
|
```sh
|
2020-08-20 09:41:51 +00:00
|
|
|
git log --pretty=oneline
|
|
|
|
git log --graph --pretty=oneline
|
|
|
|
git log --date=human
|
|
|
|
```
|
|
|
|
|
|
|
|
Changelog:
|
|
|
|
|
2020-09-28 15:30:57 +00:00
|
|
|
```sh
|
2020-08-20 09:41:51 +00:00
|
|
|
git shortlog <commit>..HEAD
|
2020-07-10 05:45:14 +00:00
|
|
|
```
|
2020-09-28 15:30:57 +00:00
|
|
|
|
|
|
|
Clean untracked files and folders:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git clean -fd
|
|
|
|
|
|
|
|
# If afraid
|
|
|
|
git clean -fdn
|
|
|
|
```
|