0

i've created a new branch called "addroles" and did a checkout to it and did some changes but when i returned to master to see the old version before i do the changes on the "addroles" i've found that they were brought to the master and waiting for commit like the new branch. I really don't know what this is related to.

khalil elloumi
  • 67
  • 2
  • 10
  • 1
    Did you commit the new changes before switching back to master ? Usually, you would stash unfinished changes when you need to switch branches. – vaugham Mar 02 '20 at 10:13
  • 1
    Does this answer your question? [Modified files in a git branch are spilling over into another branch](https://stackoverflow.com/questions/246275/modified-files-in-a-git-branch-are-spilling-over-into-another-branch) – phd Mar 02 '20 at 11:28

2 Answers2

0

In your branch addroles, do the below-

1. git stash
2. git checkout master

With this, your local changes to branch addroles will be stashed in that branch and you should be able to see the master branch without your recent changes made to addroles branch.

When you switch back to addroles branch, be sure you do

git stash apply

This will bring back your changes to your local branch. Hope this helps.

techie_questie
  • 1,434
  • 4
  • 29
  • 53
0

You made the changes while the addroles branch is in checkout, but you neither stash, nor stage, nor commit them.

That is why your changes "appear" in master when you change to it.

As @techie_questie mention you can Stash them, but also you can Stage or Commit them to the addroles branch prior to checkout master.

XtianGIS
  • 967
  • 16
  • 39