Messing up with branches, old master branch shows files from the new branch?
As you can understand I’m still learning Git and how branch works. Anyways:
- I was working on a local
- I created and switched to a new
fcwdetectionbranch for adding some code, using my IDE, meaning not through the command line.
- The IDE has asked me to add new files I created (say
A.php) to the repository. I’ve added it and modified
B.php(which was already added).
The result is that the
master branch (I switched back to it) has now
B.php has the same edits as
How is this possible? Is this an error from the IDE or I completely misunderstood how branch work?
One Solution collect form web for “Messing up with branches, old master branch shows files from the new branch?”
Your workflow seems correct. Looks like an error in the IDE. If you want to have the modified files only in the
fcwdetection branch you should commit them while you’re in that branch.
In the command line you do something like that:
Create the branch:
git checkout -b fcwdetection
A.php and create
Add all the files, included the new
git add -A .
Commit them in the
git commit -m 'Commit message'
At this point if you check back in
master you see the old versions of the files:
git checkout master
If you keep seeing the the modified versions of
B.php you should check their state, are them already added to the
index? I say so beause
git don’t let you switch from a branch to another with modified non-commited files, in the command line you get this error:
error: Your local changes to the following files would be overwritten by checkout: [some files] Please, commit your changes or stash them before you can switch branches. Aborting