Git Move - Déplacer et renommer des fichiers

VérifiéSûr

Utilise `git mv` pour déplacer ou renommer des fichiers tout en préservant l'historique Git. Automatiquement indexé, il évite les suppressions suivies d'ajouts. Pratique lors de réorganisations de code ou de refontes de structure.

Spar Skills Guide Bot
DeveloppementDébutant
12002/06/2026
Claude CodeCursorWindsurfCopilotCodex
#git#file-management#refactoring#rename#move

Recommandé pour

Notre avis

Utilise git mv pour déplacer ou renommer des fichiers tout en préservant l'historique Git et en stagant automatiquement les modifications.

Points forts

  • Préserve l'historique des fichiers en suivant les renommages
  • Stage automatiquement les changements
  • Empêche les écrasements accidentels
  • Affiche le changement comme un renommage dans git status

Limites

  • Nécessite de mettre à jour manuellement les imports vers le nouveau chemin
  • Ne gère pas automatiquement les déplacements en masse complexes
  • Fonctionne uniquement dans un dépôt Git
Quand l'utiliser

Lorsque vous déplacez ou renommez des fichiers dans un dépôt Git pour conserver l'historique et la traçabilité.

Quand l'éviter

Lorsque vous souhaitez supprimer et recréer un fichier volontairement, ou en dehors d'un environnement Git.

Analyse de sécurité

Sûr
Score qualité85/100

The skill only instructs to use `git mv` for moving/renaming files within a git repository. No external tools, destructive commands, or network operations are involved. The `-f` flag is mentioned with a caution note, but it is a standard git feature. No significant security risk.

Aucun point d'attention détecté

Exemples

Rename a component
Rename the file components/OldButton.tsx to components/Button.tsx using git mv to preserve history.
Reorganize directory structure
Move the file src/old-component.tsx to src/components/new-component.tsx using git mv, preserving history and ensuring imports are updated.

name: git-move description: Move or rename files using git mv to preserve history. Use this when moving files, renaming files, or reorganizing code structure. Always prefer git mv over regular mv or filesystem operations.

Git Move Skill

Move or rename files using git mv to preserve git history and ensure proper staging.

When to Use

  • Moving files between directories
  • Renaming files
  • Reorganizing code structure
  • Refactoring file locations

Instructions

ALWAYS use git mv instead of regular file move operations when working in a git repository.

Basic Usage

# Move a file
git mv <source> <destination>

# Examples
git mv src/old-component.tsx src/components/new-component.tsx
git mv app/page.tsx app/(home)/page.tsx
git mv utils.ts lib/utils.ts

Moving Multiple Files

# Move all files matching a pattern
git mv src/utils/*.ts lib/utils/

# Move entire directory
git mv old-directory/ new-directory/

Benefits Over Regular mv

  1. Preserves history: Git tracks the file rename
  2. Auto-stages: Change is automatically staged for commit
  3. Safe operation: Fails if destination exists (prevents overwrites)
  4. Works with git status: Shows as renamed, not deleted+added

Examples

Rename a Component

git mv components/OldButton.tsx components/Button.tsx

Reorganize Directory Structure

# Create target directory first if needed
mkdir -p components/ui

# Move files
git mv components/button.tsx components/ui/button.tsx
git mv components/input.tsx components/ui/input.tsx

Move with Force (Overwrite)

# Use -f to overwrite existing destination (use carefully)
git mv -f source.ts destination.ts

Important Notes

  • After moving, update all import statements that reference the old path
  • Run type checking (pnpm tsc --noEmit) to find broken imports
  • Consider using an IDE refactoring tool for imports if available
Skills similaires