Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Master and branch showing the same changes

Tags:

git

I am still in the process of learning Git and when I felt I have mastered it all..I encounter a problem which makes me feel a novice again...

I have a master and a branch.For some 'God only knows' reason when I perform "Git status" on both the branches they are showing the same changes.

And when I commit these changes to one of them..I don't see them in the other..

Master*: Git status
On branch Master
Changes not staged for commit:
      modified:   Config/A.txt 
Untracked files:
       logs/B.txt


**Branch-1*: Git status**
On branch Branch-1
Changes not staged for commit:
      modified:   Config/A.txt 
Untracked files:
       logs/B.txt   

you be the God,for a while, :)

like image 815
raj'sCubicle Avatar asked Jun 02 '17 14:06

raj'sCubicle


People also ask

Why are changes in one branch visible in another branch?

git add stages the changes into the index. git commit takes a snapshot of all the tracked files in the index as a commit. A branch is a ref that points to a commit. In your case, the changes are still in the work tree.


2 Answers

I guess you are switching from one branch to the other and running status, right? When you have uncommitted changes on your work tree and you ask git to switch, git will bring over the changes to the other branch you check out (at least, it tries to). There are some checks it performs and if the changes can't be applied correctly on the other branch, the switch is interrupted.

like image 134
eftshift0 Avatar answered Oct 29 '22 19:10

eftshift0


If you don't make a commit and you go to checkout master (or other branch) git will show you the same changes in both branch. But when you do the commit, these changes won't show for git in other branch, just in the branch where you are working.

like image 41
Enzo Fabricio Olrtegui Vidales Avatar answered Oct 29 '22 18:10

Enzo Fabricio Olrtegui Vidales