DEV Community

ダニエリ for WoMakersCode

Posted on • Edited on

6

[Tutorial Git] git mv: Renomeando ou movendo arquivos no Git

Para renomear um arquivo do repositório, basta digitar o comando:



$ git mv <nome_antigo> <nome_novo>


Enter fullscreen mode Exit fullscreen mode
  • o símbolo $ indica que você deve usar o usuário comum para fazer essa operação.
  • substitua o <nome_antigo> e <nome_novo> pelos nomes do arquivo e o novo nome que deseja dar a ele, sem os sinais <>

Esse comando também é usado para mover arquivos do repositório. Exemplo:



$ git mv <arquivo> <diretorio/>


Enter fullscreen mode Exit fullscreen mode

Exemplo:

Mudando o nome do arquivo nintendo64.html para n64.html.

mudando o nome do arquivo nintendo64.html

Movendo o arquivo estilo.css para o diretório css.

movendo o arquivo estilo.css

Top comments (3)

Collapse
 
jpcardoso89 profile image
João Paulo Cardoso

Ótimo artigo!! Muito obrigado por compartilhar seu conhecimento!!

Collapse
 
allenhalsay profile image
Allen Halsay

Ótimo... Eu queria aprender era fazer o inverso... No caso retornar o arquivo para a pasta anterior! :-)

Collapse
 
arthursj profile image
ArthurSilva • Edited

Boa Noite! Espero que funcione.

// Com pasta

Na raiz tendo uma pasta teste1 e dentro dela teste2 temos a seguinte hierarquia:

teste1 > teste2

Para movermos a pasta teste2 fora da pasta teste1, devemos estar dentro da pasta teste1 e declarar:

mv teste2 ../

ou

mv teste2/ ../

ou

mv ./teste2 ../

Feito isso teremos a seguinte estrutura:

// Raiz do projeto
teste1
teste2


// Arquivo

Tendo tendo a pasta 'um' e dentro dela pasta 'dois' temos a seguinte estrutura:

um > dois

Tendo um arquivo 'txt' dentro da pasta 'dois' temos a seguinte estrutura:

um > dois > index.txt

Para movermos o arquivo 'txt' para a pasta 'um', entramos na pasta 'dois' e declaramos:

mv index.txt ../

Teremos a seguinte estrutura:

// pasta um
dois
index.txt

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay