Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
- 2.43.1 → 2.45.2 no changes
- 2.43.0
11/20/23
- 2.42.1 → 2.42.3 no changes
- 2.42.0
08/21/23
- 2.39.1 → 2.41.2 no changes
- 2.39.0
12/12/22
- 2.38.1 → 2.38.5 no changes
- 2.38.0
10/02/22
- 2.35.1 → 2.37.7 no changes
- 2.35.0
01/24/22
- 2.32.1 → 2.34.8 no changes
- 2.32.0
06/06/21
- 2.31.1 → 2.31.8 no changes
- 2.31.0
03/15/21
- 2.26.1 → 2.30.9 no changes
- 2.26.0
03/22/20
- 2.24.1 → 2.25.5 no changes
- 2.24.0
11/04/19
- 2.23.1 → 2.23.4 no changes
- 2.23.0
08/16/19
- 2.22.1 → 2.22.5 no changes
- 2.22.0
06/07/19
- 2.17.1 → 2.21.4 no changes
- 2.17.0
04/02/18
- 2.16.6
12/06/19
- 2.15.4 no changes
- 2.14.6
12/06/19
- 2.13.7
05/22/18
- 2.12.5
09/22/17
- 2.11.4
09/22/17
- 2.8.6 → 2.10.5 no changes
- 2.7.6
07/30/17
- 2.1.4 → 2.6.7 no changes
- 2.0.5
12/17/14
RESUMO
git stash list [<opções-do-log>] git stash show [-u | --include-untracked | --only-untracked] [<opções-do-diff>] [<stash>] git stash drop [-q | --quiet] [<stash>] git stash pop [--index] [-q | --quiet] [<stash>] git stash apply [--index] [-q | --quiet] [<stash>] git stash branch <branchname> [<stash>] git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet] [-u | --include-untracked] [-a | --all] [(-m | --message) <mensagem>] [--pathspec-from-file=<file> [--pathspec-file-nul]] [--] [<pathspec>…]] git stash save [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet] [-u | --include-untracked] [-a | --all] [<message>] git stash clear git stash create [<mensagem>] git stash store [(-m | --message) <mensagem>] [-q | --quiet] <commit>
DESCRIÇÃO
Use git stash
when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD
commit.
The modifications stashed away by this command can be listed with git stash list
, inspected with git stash show
, and restored (potentially on top of a different commit) with git stash apply
. Calling git stash
without any arguments is equivalent to git stash push
. A stash is by default listed as "WIP on branchname …", but you can give a more descriptive message on the command line when you create one.
O último "stash" que você criou é armazenado em refs/stash
; os "stash" mais antigos são encontrados no "reflog" desta referência e podem ser nomeados usando a sintaxe usual do "reflog" (por exemplo, stash@{0}
é o "stash" criado mais recentemente, o stash@{1}
é o anterior, o stash@{2.hours.ago}
também é possível). As pilhas "stash" também podem ser referenciadas definindo apenas o índice "stash" (por exemplo, o número inteiro n
é o equivalente a um stash@{n}
).
COMANDOS
- push [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [(-m|--message) <mensagem>] [--pathspec-from-file=<arquivo> [--pathspec-file-nul]] [--] [<pathspec>…]
Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index). The <message> part is optional and gives the description along with the stashed state.
For quickly making a snapshot, you can omit "push". In this mode, non-option arguments are not allowed to prevent a misspelled subcommand from making an unwanted stash entry. The two exceptions to this are
stash -p
which acts as alias forstash push -p
and pathspec elements, which are allowed after a double hyphen--
for disambiguation.- save [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<mensagem>]
This option is deprecated in favour of git stash push. It differs from "stash push" in that it cannot take pathspec. Instead, all non-option arguments are concatenated to form the stash message.
- list [<opções-do-registro-log>]
List the stash entries that you currently have. Each stash entry is listed with its name (e.g.
stash@{0}
is the latest entry,stash@{1}
is the one before, etc.), the name of the branch that was current when the entry was made, and a short description of the commit the entry was based on.stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation stash@{1}: On master: 9cc0589... Add git-stash
O comando aceita as opções aplicáveis ao comando git log para controlar o que é exibido e como. See git-log[1].
- show [-u|--include-untracked|--only-untracked] [<opções-do-diff>] [<stash>]
Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g.,
git stash show -p stash@{1}
to view the second most recent entry in patch form). If no<diff-option>
is provided, the default behavior will be given by thestash.showStat
, andstash.showPatch
config variables. You can also usestash.showIncludeUntracked
to set whether--include-untracked
is enabled by default.- pop [--index] [-q|--quiet] [<stash>]
Remova a única condição do empilhamento da lista e aplique-o sobre a condição atual da árvore de trabalho, ou seja, faça a operação inversa do comando
git stash push
. O diretório de trabalho deve corresponder ao índice. O diretório de trabalho deve coincidir com o índice.A aplicação da condição pode falhar com conflitos; neste caso, ele não é removido da lista stash. É necessário resolver os conflitos manualmente e chamar o comando
git stash drop
manualmente depois.- apply [--index] [-q|--quiet] [<stash>]
Como
pop ', porém não remova a condição da lista de estoque 'stash'. Diferente de `pop
,<stash>
pode ser qualquer commit que se pareça com um commit criado através do comandostash push
oustash create
.- branch <nome-do-ramo> [<stash>]
Creates and checks out a new branch named
<branchname>
starting from the commit at which the<stash>
was originally created, applies the changes recorded in<stash>
to the new working tree and index. If that succeeds, and<stash>
is a reference of the formstash@{<revision>}
, it then drops the<stash>
.É útil caso o ramo onde você executou o
git stash push
mude o suficiente para que ogit stash apply
falhe devido aos conflitos. Como a entrada que está acumulada "stash" é aplicada no topo do commit que era oHEAD
no momento onde ogit stash
foi executado, ela restaura a condição originalmente armazenada e sem os conflitos.- clear
Remova todos os lançamentos que estiverem armazenados. Observe que estas entradas estarão sujeitas a remoção e podem ser impossíveis de serem recuperadas (consulte Exemplos abaixo para uma possível estratégia).
- drop [-q|--quiet] [<stash>]
Remova uma única entrada "stash" da lista das entradas "stash".
- create
Create a stash entry (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "push" above.
- store
Store a given stash created via git stash create (which is a dangling merge commit) in the stash ref, updating the stash reflog. This is intended to be useful for scripts. It is probably not the command you want to use; see "push" above.
OPÇÕES
- -a
- --all
Esta opção só é válida para os comandos
push
esave
.Todos os arquivos ignorados e não monitorados também são armazenados em cache e limpos com o comando
git clean
.- -u
- --include-untracked
- --no-include-untracked
Quando usado em conjunto com os comandos
push
esave
, todos os arquivos não monitorados também são armazenados em cache e limpos com o comandogit clean
.Quando usado com o comando
show
, mostra os arquivos não rastreados na entrada acumulada como parte do diff.- --only-untracked
Esta opção só é válida para o comando
show
.Mostra apenas os arquivos não rastreados na entrada do stash como parte do diff.
- --index
Esta opção só é válida para os comandos
pop
eapply
.Tenta restabelecer não apenas as alterações da árvore de trabalho, mas também as do índice. No entanto, isso pode falhar quando há conflitos (que são armazenados no índice e portanto, não é mais possível aplicar as alterações como eram originalmente).
- -k
- --keep-index
- --no-keep-index
Esta opção só é válida para os comandos
push
esave
.Todas as alterações que já foram adicionadas ao índice não são alteradas.
- -p
- --patch
Esta opção só é válida para os comandos
push
esave
.Interactively select hunks from the diff between HEAD and the working tree to be stashed. The stash entry is constructed such that its index state is the same as the index state of your repository, and its worktree contains only the changes you selected interactively. The selected changes are then rolled back from your worktree. See the “Interactive Mode” section of git-add[1] to learn how to operate the
--patch
mode.The
--patch
option implies--keep-index
. You can use--no-keep-index
to override this.- -S
- --staged
Esta opção só é válida para os comandos
push
esave
.Armazene apenas as alterações que estão sendo preparadas atualmente. Isto é similar ao comando
git commit
básico, exceto que o estado do commit é feito na pilha armazenada em vez do ramo atual.A opção
--patch
tem prioridade sobre esta.- --pathspec-from-file=<arquivo>
Esta opção só é válida para o comando
push
.O "pathspec" é passado com
<arquivo>
em vez dos argumentos da linha de comando. Caso o<arquivo>
seja exatamente-
, a entrada padrão será utilizada. Os elementos do "pathspec" são separados por caracteres de término de linhaLF
ouCR/LF
. Os elementos do "pathspec" podem ser citados conforme explicado na variável de configuraçãocore.quotePath
(consulte git-config[1]). Consulte também opção--pathspec-file-nul
e o global--literal-pathspecs
.- --pathspec-file-nul
Esta opção só é válida para o comando
push
.Só faz algum sentido caso seja utilizado junto com a opção
--pathspec-from-file
. Os elementos "pathspec" são separados com caracteresNUL
e todos os outros caracteres são considerados de forma literal (incluindo as novas linhas e as citações).- -q
- --quiet
Esta opção só é válida para os comandos
apply
,drop
,pop
,push
,save
estore
.Silencioso, suprima as mensagens de feedback.
- --
Esta opção só é válida para o comando
push
.Separa o pathspec das opções para fins de desambiguação.
- <pathspec>…
Esta opção só é válida para o comando
push
.The new stash entry records the modified states only for the files that match the pathspec. The index entries and working tree files are then rolled back to the state in HEAD only for these files, too, leaving files that do not match the pathspec intact.
Para mais detalhes sobre a sintaxe, consulte a entrada pathspec em gitglossary[7].
- <stash>
Esta opção só é válida para os comandos
apply
,branch
,drop
,pop
eshow
.Uma referência do formulário
stash@{<revisão>}
. Quando nenhum<stash>
é informado, o último "stash" é assumido (ou seja,stash@{0}
).
DISCUSSÃO
A stash entry is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at HEAD
when the entry was created. The tree of the second parent records the state of the index when the entry is made, and it is made a child of the HEAD
commit. The ancestry graph looks like this:
.----W / / -----H----I
onde H
é o commit HEAD
, I
é um commit que registra a condição do índice e W
é um commit que registra a condição da árvore de trabalho.
EXEMPLOS
- Obtendo de um diretório sujo
When you are in the middle of something, you learn that there are upstream changes that are possibly relevant to what you are doing. When your local changes do not conflict with the changes in the upstream, a simple
git pull
will let you move forward.However, there are cases in which your local changes do conflict with the upstream changes, and
git pull
refuses to overwrite your changes. In such a case, you can stash your changes away, perform a pull, and then unstash, like this:$ git pull ... file foobar not up to date, cannot merge. $ git stash $ git pull $ git stash pop
- Fluxo de trabalho interrompido
When you are in the middle of something, your boss comes in and demands that you fix something immediately. Traditionally, you would make a commit to a temporary branch to store your changes away, and return to your original branch to make the emergency fix, like this:
# ... hack hack hack ... $ git switch -c my_wip $ git commit -a -m "WIP" $ git switch master $ edit emergency fix $ git commit -a -m "Arruma na pressa" $ git switch my_wip $ git reset --soft HEAD^ # ... continue a hackear ...
Você pode utilizar o comando git stash para simplificar o exemplo acima:
# ... hack hack hack ... $ git stash $ edit emergency fix $ git commit -a -m "Arrumando na correria" $ git stash pop # ... continue a hackear ...
- Testando commits parciais
Você pode utilizar o comando
git stash push --keep-index
quando quiser fazer dois ou mais commits das alterações na árvore de trabalho e queira testar cada uma das alterações antes de fazer o commit:# ... hack hack hack ... $ git add --patch foo # adiciona apenas a primeira parte ao índice $ git stash push --keep-index # armazene todas as outras alterações $ edit/build/test first part $ git commit -m 'First part' # faça o commit completo de todas as modificações testadas $ git stash pop # prepare para trabalhar em todas as outras modificações # ... repita os cinco passos acima até que sobre apenas um commit ... $ edit/build/test remaining parts $ git commit foo -m 'Partes resultantes'
- Salvando as alterações não relacionadas para utilização futura
Quando estiver no meio de grandes alterações e encontre algum problema não relacionado que você não queira deixar de corrigir, você pode fazer as alterações, organizá-las e usar o comando
git stash push --staged
deixando guardado para uso posterior. Isso se assemelha ao fazer o commit das alterações acumuladas, apenas o commit acaba ficando armazenado e não no ramo atual.# ... hack hack hack ... $ git add --patch foo # adiciona alterações não relacionadas ao índice $ git stash push --staged # salva estas alterações na pilha # ... hack hack hack, conclui as alterações atuais ... $ git commit -m 'Massive' # faz o commit de das alterações totalmente testadas $ git switch fixup-branch # alterna para outro ramo $ git stash pop # para concluir o trabalho nas alterações salvas
- Recuperando entradas "stash" que foram limpas/eliminadas erroneamente
If you mistakenly drop or clear stash entries, they cannot be recovered through the normal safety mechanisms. However, you can try the following incantation to get a list of stash entries that are still in your repository, but not reachable any more:
git fsck --unreachable | grep commit | cut -d\ -f3 | xargs git log --merges --no-walk --grep=WIP
CONFIGURAÇÃO
Warning | Missing See original version for this content. |
Warning | Missing See original version for this content. |
GIT
Parte do conjunto git[1]