Re: Git: Unexpected behaviour?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 11, 2011 at 12:55:04PM -0800, Jvsrvcs wrote:
> Unexpected git behaviour
> 
[ ... switch branches with local modifications ...]
> #You will see both lines in the master.  
> 
> Question #1:
> 	Why was this line added in the *master branch?
> 

It wasn't. that line was added in the working directory. When you
switch branches, if the file in the tip of the current branch and the
file in the tip of the target branch don't differ, it's safe to keep
your local changes, so git does. This is to support the use-case where
you start editing a file when the wrong branch is checked out and want
to change to the right one.

> 
> --- even further surprising
> In the master branch, now do a commit
> $git commit -a
> 
> cat readme.txt ( you will see the line in the master now that was added in
> the test branch )
> 
> Question #2:
> 	Why did this happen?

Because you told git to commit the file with that modification in it.

> 
> # Now switch back to the test branch
> $git checkout test
> $cat readme.txt
> 
> You will only see the one line: "This was added in the master branch"
> 
> Question #3:
> 	Why did this happen?

Because the file in the 'test' branch only has that line. As you said
yourself, you edited the file but didn't commit.

> 
> and NOT the line added in that branch: "this was added in the test branch"
> <= this line is gone

Again, that line wasn't added in any branch but in the working
directory. The active branch was 'test', but doesn't magically mean
that uncommitted changes travel with it.

   cmn

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]