Reputation: 1809
We're maintaining several Git branches, we switch branch frequently because of the incoming bugs from different customers.
Sometimes, we want to keep the code change on branch01 before switching to branch02.
And next hour, we may switch back to branch01, in this case we also want to keep the work on branch02 before switching back to branch01.
This may sound strange to you, but it does happen in our daily maintenance work.
We try git stash, but it doesn't work as I expected in this case.
We also don't want to do git commit before switching to another branch because the work has not quite yet done.
I'm wondering to know, what Git process should be used to deal with this kind of situations.
Thanks!
Upvotes: 2
Views: 1845
Reputation: 2755
If you are unable to stash the changes of a new file, you need to add it first, or else it will be there when you switch branches.
You can also save a message for the stash by using:
git stash save <message>
Upvotes: 0
Reputation: 43023
I am in the same situation as you fairly often. The way I approach is committing my work before switching branches. Commits are local so they won't harm anyone until they are pushed.
When I return to the original branch to continue the work I committed early, I just do what I need to do and when the time for adding new changes comes, I amend my commit to keep all changes in one commit:
git commit --amend
This keeps the history clean and you push only one commit with all your changes.
See more on amending for example here.
Upvotes: 2
Reputation: 31
For you can switch of branch you need commit your changes, git not save changes that don't commit, you can find this in progit book
Upvotes: 0