Use pelican page/static linking
This commit is contained in:
61
content/cheat-sheets/git.md
Normal file
61
content/cheat-sheets/git.md
Normal file
@ -0,0 +1,61 @@
|
||||
---
|
||||
Title: Some git tricks
|
||||
Date: 2019-04-22 17:00
|
||||
Modified: 2019-04-24 20:08+05:30
|
||||
Author: Fabrice
|
||||
Category: cheat sheets
|
||||
Tags: git, termtosvg
|
||||
Slug: git-tricks
|
||||
Header_Cover: images/covers/water.jpg
|
||||
Summary: A compilation of some `git` tricks I keep forgetting.
|
||||
Lang: en
|
||||
---
|
||||
|
||||
Some [git](https://git-scm.com/) tricks I use from time to time and that I forgot everytime…
|
||||
|
||||
**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]({filename}/software/pass.md), therefore most of those commands are here to fix my own mistakes.
|
||||
|
||||
Reset `master` to `origin/master`:
|
||||
```sh
|
||||
git checkout origin/master -B master
|
||||
```
|
||||
|
||||
Jump back and forth from a commit to another (same behaviour as :
|
||||
```sh
|
||||
git checkout -
|
||||
```
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
To add changes in an atomic fashion on a file (in an interactive way):
|
||||
```sh
|
||||
git add -p <file>
|
||||
```
|
||||
|
||||
**Unsafe:** to remove a file from the past (for instance when you commit some *sensitive* file):
|
||||
```sh
|
||||
git filter-branch --prune-empty --tree-filter "rm -f '<file name>'" HEAD
|
||||
git push --force
|
||||
```
|
||||
|
||||
Another useful trick is `git commit -v`, it allows reviewing your changes before committing.
|
||||
|
||||
<object data="/examples/git-cv.svg" width="100%">Use of git commit -v</object>
|
||||
|
||||
A ncurse-based interface for git: [tig](https://jonas.github.io/tig/)
|
||||
```sh
|
||||
tig
|
||||
```
|
||||
|
||||
<!-- vim: spl=en
|
||||
-->
|
Reference in New Issue
Block a user