blog/content/chs-git.md

36 lines
1.2 KiB
Markdown
Raw Normal View History

2019-04-22 11:35:20 +00:00
---
2019-04-22 13:44:16 +00:00
Title: Some git tricks
Date: 2019-04-22 17:00
Author: Fabrice
Category: cheat sheets
2019-04-22 15:15:19 +00:00
Slug: git-tricks
2019-04-22 13:44:16 +00:00
Header_Cover: images/cover_water.jpg
2019-04-22 11:35:20 +00:00
---
2019-04-22 15:15:19 +00:00
Some [git](https://git-scm.com/) tricks I use from time to time and that I forgot everytime…
2019-04-22 11:35:20 +00:00
2019-04-22 15:27:43 +00:00
**Disclaimer:** I'm not the perfect git user, and my way of using it is especially crude.
Recently, most of my git commits are due to [`pass`](/password-store.html), therefore most of those commands are here to fix my mistakes.
2019-04-22 11:35:20 +00:00
Reset `master` to `origin/master`:
```sh
git co origin/master -B master
```
2019-04-22 15:27:43 +00:00
Find back lost commits, especially useful when you are doing dirty things and want to `cherry-pick` an orphan commit (for instance):
```sh
git log --graph --reflog
```
Some explanations: `--graph` show the commit tree, which is useful to notice the orphan leafs, and `--reflog` shows the world all the dirtiness you've done.
If you noticed that your folder grows, you can manually cast the garbage collector on it. It should do it automatically, but not often enough according to my standards.
```sh
git gc --aggressive
```
2019-04-22 11:35:20 +00:00
Another useful trick is `git commit -v`, it allows reviewing your changes before committing.
![Example](/examples/git-cv.svg)
2019-04-22 15:27:43 +00:00