Reputation: 21
I have to checkout from one branch of the project to the other. When I do it, it adds all the added files in the changed branch also. I don't want to commit those files from this branch. What should I do and how should I avoid this thing in future
A ui/.gitignore
A ui/README.md
A ui/babel.config.js
A ui/package-lock.json
A ui/package.json
A ui/public/favicon.ico
A ui/public/index.html
A ui/src/App.vue
A ui/src/assets/logo.png
A ui/src/components/HelloWorld.vue
A ui/src/main.js
Already on 'added_more_notification_channels'
Upvotes: 1
Views: 1474
Reputation: 487755
It doesn't.
Instead, what Git does is simpler:
You then asked Git: Please switch from the commit at the tip of master
to the commit at the tip of added_more_notification_channels
. (I had to guess at one branch name, but it does not really matter much here.)
In some cases, Git will say: Sorry, I can't do that: if I did that I'd destroy your updated files by replacing them with copies from the commit at the tip of added_more_notification_channels
.
In other cases, Git will say: OK, I did that ... but IMPORTANT NOTE: I didn't destroy your updated files, I left them alone. They now don't match the commit at the tip of added_more_notification_channels
, just like they didn't match the commit at the tip of master
before. If you had meant to add and commit them to master
, you can now git checkout master
again to get back to where you were. If not, you're good where you are, with your modified files still modified.
If you're curious about why sometimes Git says: OK, I've switched branches! (I took your modified files along for the ride!) and sometimes says Whoops, sorry, I can't do that! That would destroy your modified files!, see Checkout another branch when there are uncommitted changes on the current branch.
(Actually, it looks like you asked Git: Please switch from added_more_notification_channels
to added_more_notification_channels
, which is no switch at all, and therefore always works!)
Upvotes: 2
Reputation: 1203
If you add/modify/delete
some files then you can get those files at another branch. So if you want to checkout another branch first you have to commit the changed files. Then you can checkout another branch. And if you don't commit, then you will get those file to the checkout branch.
So you should follow these steps -
Upvotes: 0