GIT Change branch without committing or discarding current changes

4

I need to send my current changes to another branch.

When giving git checkout branch-name it asks me to commit or change the current changes, I do not want any of these options.

How can I proceed?

    
asked by anonymous 18.05.2017 / 22:44

1 answer

3

If you want to save the changes you have made, you can do a git stash and you'll see something like:

$ git stash
Saved working directory and index state \
  "WIP on master: 049d078 added the index file"
HEAD is now at 049d078 added the index file
(To restore them type "git stash apply")

, this will be done in stack and you can do git checkout without problems.

$ git status
# On branch master
nothing to commit, working directory clean

If you want to continue the changes saved in stash , type git stash list and something like:

$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051... Revert "added file_size"
stash@{2}: WIP on master: 21d80a5... added number to log

Then just select one with git stash apply to select the most recent, or for example to select a specific stash from the list:

git stash apply stash@{2}

$ git stash apply
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#
#      modified:   index.html
#      modified:   lib/simplegit.rb
#
    
18.05.2017 / 22:55