Kilka przydatnych trików w gicie. Dzisiaj pierwszy
Autostash
Często gdy chcemy robić git rebase okazuje się że mamy jakieś nie zakomitowa pliki i okazuje się że musimy zrobić stash, potem rebase i na końcu stash pop. Proste ale czasochłonne. Git ma na to lekarstwo: autostash
W dokumentacji git znajdziemy coś takiego:
rebase.autoStash
When set to true, automatically create a temporary stash entry before the operation begins, and apply it after the operation ends. This means that you can run rebase on a dirty worktree. However, use with care: the final stash application after a successful rebase might result in non-trivial conflicts. This option can be overridden by the--no-autostash
and--autostash
options of git-rebase[1]. Defaults to false.
Przykład z życia:
17:43 $
✘-1 ~/sources/sudoku/sudoku-app [master ↑·2|✚ 8…2]
17:43 $ git rebase
Cannot rebase: You have unstaged changes.
Please commit or stash them.
Jak widać rebase się nie udał. Można tradycyjnie git stash i ponowić rebase ale można aktywować autostash w następujący sposób:
✘-1 ~/sources/sudoku/sudoku-app [master ↑·2|✚ 8…2]
17:43 $ git config --global rebase.autostash true
Ok, ustawione to teraz rebase:
✔ ~/sources/sudoku/sudoku-app [master ↑·2|✚ 8…2]
17:43 $ git rebase
Created autostash: 1723d55
HEAD is now at b23d7dc TECH 0px -> 0
First, rewinding head to replay your work on top of it…
Applying: fly way added
Applying: TECH 0px -> 0
Applied autostash.
i bez ręcznego git stash/git stash pop mamy zrobiony rebase! Oczywiście nie zawsze musi się to udać bo git stash pop może się skonfliktować ale to już inna historia.
Dokumentacja: https://git-scm.com/docs/git-rebase#git-rebase-rebaseautoStash