Git - stash przechowywanie zmian bez commita

Autor podstrony: Krzysztof Zajączkowski

Stronę tą wyświetlono już: 617 razy

Nie chcesz jeszcze commitować? Nie ma co się denerwować! Jest stash wszakże. Oto jak możesz z niego skorzystać w celu zapamiętania twoich zmian, do których za chwilę będziesz chciał wrócić:

git stash push -m "some comment to know what this things is about"

A teraz jeżeli potrzebujesz wyświetlić listę zachowanych w Git-cie zmian schowanych na potem:

git stash list
stash@{0}: On 005_add_merging_operations_types: some comment to know what this things is about

Jeżeli wiesz, że nie będziesz dodawał nowych a chcesz szybko dodać coś do stash-a to wystarczy:

git stash

Chcesz zdjąć ostatni? No problemos amigos:

git stash pop
On branch 005_add_merging_operations_types
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   todo.txt

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (3733346cd332874abd5dfa0a9beedd7170723175)

Tak jak w przypadku tablic w programowaniu pop ściąga i zwraca ostatnio dodany element do stash-a. Jeżeli chcesz wybrać konkretny element musisz użyć jego indeksu i polecenia:

git stash apply 1

Lista zachowanych zmian przed użyciem apply:

git stash list
stash@{0}: WIP on 005_add_merging_operations_types: 9d2feaf add style for ul elements
stash@{1}: WIP on 005_add_merging_operations_types: 9d2feaf add style for ul elements
stash@{2}: On 005_add_merging_operations_types: my description
stash@{3}: WIP on 005_add_merging_operations_types: 9d2feaf add style for ul elements
stash@{4}: WIP on 005_add_merging_operations_types: 9d2feaf add style for ul elements

Co ważne lista zostaje zachowana w tej samej konfiguracji po użyciu apply.

Jeżeli chcesz zdjąć określony element i dodać wyświetlić to pop z indeksem jest tym czego szukasz:

git stash pop 2

Czyszczenie stash:

git stash clear