Reputation: 8673
When I reset one branch, it also is resetting the others. For example, say I have been working on featureA
for a while, and I need to start on a new feature. So naturally I do
git branch featureB
git checkout featureB
Oh no, all my edits from featureA
are here! So I do git reset -hard upstream/dev
or git checkout -- .
Seems to work, gets rid of all featureA
stuff. But then when I'm done and I want to go back...
git checkout featureA
git status
All my work on featureA
is now gone. :(
Upvotes: 3
Views: 1866
Reputation: 11190
git reset --hard
is a destructive operation, and it is advised not to use it if you do not know what you are doing.
To save your work before checking you branch you can do
git stash
When you return you can reapply your changes with git stash pop
.
If you haven't committed you changes in feature A than it is lost. If you did, you can check git reflog
for the commit hash that you want to return to.
Upvotes: 2
Reputation: 20232
Are you in the featureA
branch when you create the featureB
branch? If so that makes sense that all your featureA
stuff is there.
You should branch off your dev branch such as
git checkout -b featureB dev
which will create your branch off of your dev branch, as opposed to a continuation of the featureA branch.
Upvotes: 2