Pular para o conteúdo

What’s git stash

Hello, hello!

In this post, I will explain how to use the git command stash.

This is a useful command when you need to pause your progress and keep it saved without committing, for example, to work on an emergency update of the latest released version.

When you stash a change, the modifications are “save” or “hide” from the main files, then you are free to do what you want.

Olá!

Nessa publicação, eu vou explicar como utilizar o comando stash do git.

Esse é um comando bem útil quando você precisa parar o seu progresso e necessita mantê-lo salvo sem realizar commit, por exemplo, para trabalhar em uma atualização de emergência.

Quando você stash uma mudança, as modificações são “salvas” ou “escondidas” dos arquivos principais e então você estará livre para fazer o que necessita realizar.

How to use

Como usar

In your branch, use stash and the following message about your wip (work in progress) will be shown.

Na sua branch, use o comando stash e a seguinte mensagem de wip (work in progress) será exibida.

$ git stash
Saved working directory and index state WIP on master: 03eb1cc my first commit

In this moment, you are free to work on others things.

Nesse momento, você estará livre para trabalhar em outras coisas.

When you’re finished, you can go back to your branch and apply the changes from your stash using the commands pop or apply.

Quando você finalizar suas atividades, você pode voltar para sua branch e aplicar as mudanças do seus stash usando os comandos pop ou apply.

git stash pop 
git stash apply

Multiple stashes

Múltiplos stashes

One important thing, you can have multiple stashes.

Um ponto importante, você pode criar múltiplos stashes.

A good practice is to use a message to identify your stashes, for that, use the command save “message”.

Quando criar um stash uma boa prática é identificar seus stashes, para isso, use o comando save “message”.

git stash save “message”

By default, when you use the command pop to apply the changes, it will apply the last created stash.

Por padrão, quando usamos o comando pop para aplicar as alterações, ele irá aplicar o último stash criado.

To see others stashes you’ve created use the command list.

Para visualizar todos os stashes criados use o comando list.

git stash list

To apply a specific stash from the list, you can use the command pop stash with its corresponding key from the list.

Para aplicar um stash específico, você pode usar o comando pop stash junto com a chave desejada.

git stash pop stash@{2}

Clean your stash

Apagar seu stash

If you don’t need a stash anymore, you can delete it using the command drop and apply its corresponding key from the list.

Se você não necessitar mais de um stash, você pode apagá-lo com o comando drop junto com a chave desejada.

git stash drop stash@{1}

Now, if you want to delete all stashes, use the command clear.

Agora, se você deseja apagar todos os stashes, use o comando clear.

git stash clear

Well, this is a simple tutorial to explain how to use the stash on git and maybe help you save some time.

Bem, este é um simples tutorial para explicar como utilizar o comando stash, espero que seja útil e que ajude de alguma forma.

I hope you enjoy.

Espero que tenha gostado.

Bye, bye! 🖖🏾

Um cheiro! 🖖🏾