git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git branches - confusing behavior

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
May 11, 2008, 12:57 UTC
Message-ID
<20080511125722.GA22075@atjola.homenet>
In-Reply-To
<4826E791.7030407@gmail.com>
On 2008.05.11 15:33:21 +0300, Dima Kagan wrote:
Show 12 quoted lines
> >> Basically I see that the same file I edited on the 'test_branch'
> >> branch appears to be modified on the 'master' branch as well. This
> >> behavior is unwanted, of course.
> >>
> >> Can someone please tell me, what am doing wrong? Or is this git's
> >> normal behavior?
> > 
> 
> I just realized that this behavior is even more confusing.  If I
> commit the file on 'test_branch' and only then 'git checkout master'
> the changes are not visible on 'master' until I merge. So why should
> 'master' be affected by uncommitted changes on some branch???

Uncommitted changes are not on any branch, they are in your working tree and/or your index. And actually, SVN does the exact same thing.

# Create a SVN repository with trunk/ and branches/ # ---- $ mkdir svn $ cd svn $ svnadmin create repo $ export REPO="file://$PWD/repo" $ svn co $REPO wc Checked out revision 0. $ cd wc $ svn mkdir trunk branches A trunk A branches $ svn commit -m init Adding branches Adding trunk

Committed revision 1. $ svn switch $REPO/trunk D trunk D branches Updated to revision 1.

# Create some content in trunk # ---- $ echo 123 > testfile $ svn add testfile A testfile $ svn commit -m test Adding testfile Transmitting file data . Committed revision 2.

# Create a branch # ---- $ svn cp $REPO/trunk $REPO/branches/b1 -m branch

Committed revision 3.

# Produce some uncommitted changes on trunk # ---- $ echo 456 > testfile $ svn st M testfile $ svn diff

Index: testfile
===================================================================
--- testfile    (revision 2)
+++ testfile    (working copy)
@@ -1 +1 @@
-123
+456


# Switch to the branch
# ----
$ svn switch $REPO/branches/b1
At revision 3.
$ svn st
M      testfile
$ svn diff
Index: testfile
===================================================================
--- testfile    (revision 3)
+++ testfile    (working copy)
@@ -1 +1 @@
-123
+456


The uncommitted changes survived the branch change and are still in the
working tree, in svn just like in git.

Björn
Previous: Dima KaganNext: Dima Kagan
Message 11 of 19 in “Git branches - confusing behavior”
  1. Dima KaganMay 11, 2008
  2. Jakub NarebskiMay 11, 2008
  3. Dima KaganMay 11, 2008
  4. David SymondsMay 11, 2008
  5. Dima KaganMay 11, 2008
  6. David SymondsMay 11, 2008
  7. Dima KaganMay 11, 2008
  8. Steve FrécinauxMay 11, 2008
  9. Jakub NarebskiMay 11, 2008
  10. Dima KaganMay 11, 2008
  11. Björn SteinbrinkMay 11, 2008
  12. Dima KaganMay 11, 2008
  13. Björn SteinbrinkMay 11, 2008
  14. Dima KaganMay 11, 2008
  15. Teemu LikonenMay 11, 2008
  16. Miles BaderMay 12, 2008
  17. Theodore TsoMay 11, 2008
  18. Dima KaganMay 11, 2008
  19. Patrick AljordMay 11, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.