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

给你一囗甜甜゛ 提交于 2019-12-20 07:16:45

问题


I have a master branch:

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

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

I have no clue why it happens.

Any suggestions how to return it back to norm?


回答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.




回答2:


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


来源:https://stackoverflow.com/questions/50949960/why-when-i-make-a-change-in-x-branch-my-master-branch-is-changing-as-well-in-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!