Search code examples
gitegit

egit: changes made in one branch are visible on another branch without any commit


I am using egit and this is what I see. Don't really understand how this works

From master, switch to a new branch. Make changes to existing files, modify files.

Switch to master, all changes are seen on master.

(No prompt, that need to commit changes before switching)


Solution

  • This is not a problem with egit, but the default behavior for how git works in general.

    If you make some changes, and do not add/commit them into git, then they are applied to any branch you checkout next.

    Only when the changes can not be automatically applied on checkout will you receive an error asking you to either stash your changes, or telling you that the file to be checked out already exists and hence checkout cannot proceed.

    So if you make changes when on another branch and want to keep those changes in that branch only, add and commit them. Alternatively, you can stash your changes as well.