git rebase -i HEAD~3 # Modifier les 3 derniers commits
Travailler avec des branches distantes
Récupérer toutes les branches distantes
git fetch --all
Suivre une branche distante
git checkout -b ma_branche origin/ma_branche
Supprimer une branche distante
git push origin --delete ma_branche
Stashing (mettre de côté des modifications)
Sauvegarder des modifications temporairement
git stash
Lister les stashes disponibles
git stash list
Restaurer le dernier stash
git stash pop
Restaurer un stash spécifique
git stash apply stash@{1}
Supprimer un stash spécifique
git stash drop stash@{1}
Supprimer tous les stashes
git stash clear
Recherche et inspection
Trouver un commit par message
git log --grep="mot-clé"
Trouver un commit qui a modifié un fichier spécifique
git log -- <nom_fichier>
Voir les différences entre commits
git diff HEAD~1 HEAD
Voir les différences entre le fichier modifié et la dernière validation
git diff <fichier>
Suppression et nettoyage
Supprimer un fichier du repository mais le garder localement
git rm --cached <fichier>
Supprimer un fichier complètement du repository
git rm <fichier>
Revenir en arrière
Annuler un commit et garder les modifications
git reset --soft HEAD~1
Annuler un commit et supprimer les modifications
git reset --hard HEAD~1
Revenir à un commit spécifique
git reset --hard <commit_hash>
Cherry-picking (récupérer un commit spécifique d’une branche)
git cherry-pick <commit_hash>
Bisect (trouver l’origine d’un bug)
git bisect startgit bisect bad # Marque la version actuelle comme contenant le buggit bisect good <commit_hash> # Marque une version correctegit bisect run <script> # Exécute un script pour tester chaque versiongit bisect reset # Terminer le bisect