0 votes
1 view
in DevOps and Agile by (20k points)
edited by

I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives me,

error: You have local changes to "X"; cannot switch branches.

I thought that I could change branches without committing. If so, how can I set this up? If not, how do I get out of this problem? I want to ignore the minor changes without committing and just change branches.

1 Answer

0 votes
by (119k points)
edited by

If you want to discard the changes,

git checkout -- <file>

git checkout branch

If you want to keep the changes,

git stash save

git checkout branch

git stash pop

Also, check out this Git Tutorial to know more.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...