Sometimes in the process of work I need to switch to another branch (for example, to fix a bug), respectively, when I switch to another branch, all the changes are pulled into this branch and interfere with my work.

Is it possible to change this in some way so that uncommitted changes remain in the previous branch?

1 answer 1

You can β€œhide” (stash) changes made using the same command. it has many sub-commands (see man git-stash ).

  1. hide changes (if no sub-command is specified, then save implied):

     $ git stash Saved working directory and index state WIP on Π²Π΅Ρ‚ΠΊΠ°: Ρ…ΡΡˆ описаниС ΠΊΠΎΠΌΠΌΠΈΡ‚Π° HEAD is now at Ρ…ΡΡˆ описаниС ΠΊΠΎΠΌΠΌΠΈΡ‚Π° 
  2. look at the hidden list sub-command:

     $ git stash list stash@{0}: WIP on Π²Π΅Ρ‚ΠΊΠ°: Ρ…ΡΡˆ описаниС ΠΊΠΎΠΌΠΌΠΈΡ‚Π° 
  3. extract the hidden sub-command pop :

     $ git stash pop On branch Π²Π΅Ρ‚ΠΊΠ° Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: Ρ„Π°ΠΉΠ» no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (3acbab1c34d0559dcb264fe443471a7ff20aa319) 

    the last line indicates that the β€œhidden” is removed from the β€œpantry”. you can not delete, replacing the sub-command pop sub-command apply .


more details:

  • 3
    git worktree is our everything. stash is inconvenient for many (not for people, but for reasons), but is good for one, two changes. If there are more than a dozen komits in the temporary storage from a wide variety of branches, then oh. - 0andriy