BensonLiao/blog

How to move to another branch and put aside working changes without losing it in Git?

Opened this issue · 0 comments

  1. First, of course you can actually push changes to the remote and do git reset/revert/rebase or just change code onward.
  2. Using git stash to keep a stash of your working changes, a restore from it.
    There's some major situation when create and restore from stashes:
    note. in fact git can store more than 1 stash, git stash list will tell you the stashes you created
    note. so the following restore command are short-hand for the last stash you created, if you want to specify other stash, check doc
  • create stash to record only modified files
    git stash
  • create stash to record modified files include un-tracking files
    git stash -u
  • restore only un-staged changes
    git stash apply
  • restore only staged and un-staged changes (when you run git add <files_or_dirs>, those files or dirs will staged)
    git stash apply --index