Virtual Device
Virtual Device

Reputation: 2060

Why when I make a change in 'X' branch my master branch is changing as well in the same way?

I have a master branch:

enter image description here

Then I make employee branch from the master and change it a bit:

enter image description here

And when I swipe between branches, the master branch also had been changed:

enter image description here

I have no clue why it happens.

Any suggestions how to return it back to norm?

Upvotes: 5

Views: 2377

Answers (3)

Rubel Biswas
Rubel Biswas

Reputation: 1444

Make sure you commit to the "X" branch. After you commit to the "X" branch, no change will take place in the main/master branch. But if you switch the master branch without committing to the "X" branch, changes will also be seen in the master branch.

Upvotes: 1

When you make a change in your editor, you only modify the code in your "working directory". When you switch branches, those changes in your "dirty" directory come along for the ride.

Once you commit your changes on a given branch, switching branches will no longer bring those changes over.

(Answer By @Joseph Silber)

Before your case you have three options to make:

A) Maintain changes in the master branch

# Agree 
git add file/path/archive
# Perfom a commit
git commit -m "Message"

B) Return branch employee and add changes in this branch

# Since the terminal gitbash or the manually form
git checkout employee
# Agree 
git add file/path/archive
# Perfom a commit
git commit -m "Message" 

C) Discard all change

This step will undo all changes that have not been previously added to a commit. Caution!!.

git checkout file/path/archive

Upvotes: 1

Joseph Silber
Joseph Silber

Reputation: 220146

When you make a change in your editor, you only modify the code in your "working directory". When you switch branches, those changes in your "dirty" directory come along for the ride.

Once you commit your changes on a given branch, switching branches will no longer bring those changes over.

Upvotes: 8

Related Questions