Reputation: 1213
This is my first time using git and I hope I didn't make a huge mistake.
I worked a couple of hours on my files on the master branch.
I created a branch to work into a different direction which I then decided not to do. So no files were edited in this new branch.
So I deleted the new branch.
Now all my changes I have done the last hours are gone in the master branch and I am back to the state of my last commit.
I had not committed anything till the point I created the branch.
Are all my changes lost now?
I though the master branch would not even be touched when working around with a second branch and when I delete it git would still waiting for the changes to commit.
Really hope you can help me here. I am working with the github app on mac.
Let me guess what happened:
Thesis: Never switch to branch without having committed your changes first.
I guess when I created a second branch, of course this branch will be created out of last commit. So everything is already set back to the last commit. So switching back to the master branch means the same. No files here to be tracked cause everything is back to the state of the last commit.
Am I right?
So that means there is a huge risk of loosing data, when you don't always commit your changes. And you always should commit before you switch branches. Right?
Upvotes: 0
Views: 74
Reputation: 1791
Switching branches carries uncommitted changes with you. Hence github feels the changes you made are a part of the test branch and not master branch. Either commit first, run git checkout . to undo them, or run git stash before switching. (You can get your changes back with git stash apply).
In your scenario the file changes are gone since you haven't committed nor stashed.
Upvotes: 1