Compare commits
2 Commits
f12bf523ef
...
5d45cdd544
Author | SHA1 | Date | |
---|---|---|---|
5d45cdd544 | |||
d7db410a4e |
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
Title: Quelques astuces git
|
||||
Date: 2019-04-22 17:00
|
||||
Modified: 2019-04-24 20:08+05:30
|
||||
Modified: 2023-05-14 20:00+02:00
|
||||
Author: Fabrice
|
||||
Category: antisèches
|
||||
Tags: git, termtosvg
|
||||
|
@ -11,10 +11,14 @@ Summary: Une compilation de commandes git que j’utilise ponctuellement
|
|||
Lang: fr
|
||||
---
|
||||
|
||||
Quelques astuces [git](https://git-scm.com/) que j’utilise de temps en temps que j’oublie tout le temps…
|
||||
Quelques astuces [git](https://git-scm.com/) que j’utilise de temps en temps que
|
||||
j’oublie tout le temps…
|
||||
|
||||
**Attention :** Je ne suis pas un exemple à suivre comme utilisateur de git, et mes manières sont parfois un peu crues.
|
||||
Récemment, la majorité de mes commits sont dues à [pass]({filename}/software/pass-fr.md), et donc la plupart du temps, je suis en train de réparer mes propres erreurs.
|
||||
**Attention :** Je ne suis pas un exemple à suivre comme utilisateur de git, et
|
||||
mes manières sont parfois un peu crues.
|
||||
Récemment, la majorité de mes commits sont dues à
|
||||
[pass]({filename}/software/pass-fr.md), et donc la plupart du temps, je suis en
|
||||
train de réparer mes propres erreurs.
|
||||
|
||||
Remettre la branche master `master` sur la branche distante `origin/master` :
|
||||
```sh
|
||||
|
@ -27,11 +31,14 @@ git checkout -
|
|||
```
|
||||
|
||||
|
||||
Retrouver les commits disparus, c’est très utile lorsqu’on a envie de `cherry-pick` un commit orphelin qu’on a oublié il y a quelque temps :
|
||||
Retrouver les commits disparus, c’est très utile lorsqu’on a envie de
|
||||
`cherry-pick` un commit orphelin qu’on a oublié il y a quelque temps :
|
||||
```sh
|
||||
git log --graph --reflog
|
||||
```
|
||||
Quelques explications s’imposent : `--graph` montre l’arbre des commits, ce qui se montre utile pour révéler les feuilles orphelines, et `--reflog` mets au jour tous nos secrets les plus sordides.
|
||||
Quelques explications s’imposent : `--graph` montre l’arbre des commits, ce qui
|
||||
se montre utile pour révéler les feuilles orphelines, et `--reflog` mets au jour
|
||||
tous nos secrets les plus sordides.
|
||||
|
||||
Vous avez peut-être remarqué que vos répertoires git prennent du volume.
|
||||
Pour corriger ça, on peut manuellement appeler le ramasse-miette de notre dépôt.
|
||||
|
@ -44,13 +51,15 @@ Pour ajouter un changement atomique dans un fichier (de manière interactive):
|
|||
```sh
|
||||
git add -p <file>
|
||||
```
|
||||
**Unsafe :** pour réécrire le passé en supprimant un fichier (par exemple si on a commité un donnée *sensible*):
|
||||
**Unsafe :** pour réécrire le passé en supprimant un fichier (par exemple si on
|
||||
a commité un donnée *sensible*):
|
||||
```sh
|
||||
git filter-branch --prune-empty --tree-filter "rm -f '<fichier>'" HEAD
|
||||
git push --force
|
||||
```
|
||||
|
||||
Une autre astuce utile : `git commit -v`, qui permet de réviser nos changements avant de commiter.
|
||||
Une autre astuce utile : `git commit -v`, qui permet de réviser nos changements
|
||||
avant de commiter.
|
||||
Une image vaut mieux que mille mots :
|
||||
|
||||
<object data="/examples/git-cv.svg" width="100%">Utilisation de git commit -v</object>
|
||||
|
@ -60,3 +69,27 @@ Une interface ncurses pour git : [tig](https://jonas.github.io/tig/)
|
|||
tig
|
||||
```
|
||||
|
||||
Pour pouvoir lire les `diff`s plus facilement dans git, je recommande aussi
|
||||
d’utiliser `delta` : <https://github.com/dandavison/delta>.
|
||||
Ce programme permet de rendre la lecture de la sortie de `git diff` proche de ce
|
||||
qu'on peut retrouver dans une forge en ligne comme Gitlab en mettant en
|
||||
surbrillance l’endroit exact où a eu lieu la différence.
|
||||
|
||||
Une fois le paquet installé (sous le nom de `git-delta`, en tout cas sous
|
||||
[archlinux](https://archlinux.org/)), il suffit de configurer git via :
|
||||
```gitconfig
|
||||
[core]
|
||||
pager = delta
|
||||
[interactive]
|
||||
diffFilter = delta --color-only
|
||||
[delta]
|
||||
navigate = true # n et N pour se déplacer entre les blocs
|
||||
light = true # pour les terminaux à fond clair
|
||||
theme=Monokai Extended Light
|
||||
[merge]
|
||||
conflictstyle = diff3
|
||||
[diff]
|
||||
colorMoved = default
|
||||
```
|
||||
Qui est une configuration très proche de celle proposée sur le dépôt GitHub du
|
||||
projet.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
Title: Some git tricks
|
||||
Date: 2019-04-22 17:00
|
||||
Modified: 2019-04-24 20:08+05:30
|
||||
Modified: 2023-05-14 20:00+2:00
|
||||
Author: Fabrice
|
||||
Category: cheat sheets
|
||||
Tags: git, termtosvg
|
||||
|
@ -11,10 +11,13 @@ 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…
|
||||
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.
|
||||
**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
|
||||
|
@ -26,13 +29,17 @@ Jump back and forth from a commit to another (same behaviour as :
|
|||
git checkout -
|
||||
```
|
||||
|
||||
Find back lost commits, especially useful when you are doing dirty things and want to `cherry-pick` an orphan commit (for instance):
|
||||
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.
|
||||
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.
|
||||
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
|
||||
```
|
||||
|
@ -42,13 +49,15 @@ To add changes in an atomic fashion on a file (in an interactive way):
|
|||
git add -p <file>
|
||||
```
|
||||
|
||||
**Unsafe:** to remove a file from the past (for instance when you commit some *sensitive* 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.
|
||||
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>
|
||||
|
||||
|
@ -57,5 +66,25 @@ A ncurse-based interface for git: [tig](https://jonas.github.io/tig/)
|
|||
tig
|
||||
```
|
||||
|
||||
<!-- vim: spl=en
|
||||
-->
|
||||
To make `diff`s more readable, I highly recommend to use delta as a diff filter:
|
||||
<https://github.com/dandavison/delta>.
|
||||
It makes the display of `git diff` close to what you can get in a browser
|
||||
repository, highlighting the places where diffs actually happen and is highly
|
||||
reconfigurable.
|
||||
|
||||
Once it is installed in your package manager, you can for instance configure it
|
||||
as follows (mostly the same as in the GitHub page):
|
||||
```gitconfig
|
||||
[core]
|
||||
pager = delta
|
||||
[interactive]
|
||||
diffFilter = delta --color-only
|
||||
[delta]
|
||||
navigate = true # use n and N to move between diff sections
|
||||
light = true # set to true if you're in a terminal w/ a light background
|
||||
theme=Monokai Extended Light
|
||||
[merge]
|
||||
conflictstyle = diff3
|
||||
[diff]
|
||||
colorMoved = default
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue
Block a user