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

Re: My first git success [not quite]

From
sean <seanlkml@sympatico.ca>
Date
Jan 14, 2006, 15:55 UTC
Message-ID
<BAYC1-PASMTP10B423DC1B2FC1F8C9992BAE190@CEZ.ICE>
In-Reply-To
<dqb5vg$a09$1@sea.gmane.org>

On Sat, 14 Jan 2006 07:39:28 -0800 walt <wa1ter@myrealbox.com> wrote:

Show 35 quoted lines
> Linus Torvalds wrote:
> > 
> > On Fri, 13 Jan 2006, walt wrote:
> >> And it was all so easy I never broke a sweat.  Amazing!
> 
> >  ...Most people don't bother to 
> > explain their problems well...
> 
> I see I still have a problem:  my mental model of how git
> works is still wrong.
> 
> I used 'git-checkout -b test' to create a disposable place
> to test the patch I was given.
> 
> Okay, making sure I'm now sitting in 'test', I apply the
> patch to foo.c and do my testing.
> 
> Now, intending to delete my 'test' branch, I do git-checkout
> master.  My mental model predicts that 'master' should still
> be identical to 'origin' because I did the patching in 'test'.
> Am I right so far?
> 
> The problem I see is that, after switching back to 'master',
> foo.c is the patched version, not your original version.  I
> figured that the git-checkout would overwrite any changes I
> made to foo.c, but that doesn't seem to be the case.  To get
> your original version back I had to delete foo.c and do a
> git-checkout foo.c (or git-checkout -f master).
> 
> So, I clearly don't understand what git-checkout does.  It
> doesn't seem to touch the already-checked-out sources at
> all, which is what I would expect it to do.
> 
> Can someone hit me with the clue-stick here?  Thanks!
> 
Hi Walt,

When you switch branches _uncommitted_ changes will stay in your working directory. This lets you change to a different branch before committing something you're working on for instance. So likely, even though you had switched to your test branch to apply the patch, you didn't actually commit it into that branch before switching back to master.

Here's a little example that should show the difference:
Create a test repo:
	$ mkdir walt ; cd walt
	$ git-init-db
	defaulting to local storage area
Create a simple file and commit it on the master branch:
	$ echo A > file
	$ git add file
	$ git commit -m "initial"
	Committing initial tree a9e3325a07117aa5381e044a8d96c26eb30d729d
Create and checkout a new branch named "test":
	$ git checkout -b test
	$ git branch
	  master
	* test
Modify (ie. patch) the file:
	$ echo B > file
	$ cat file
	B
Now, if you switch back to the master branch, the file is still patched:
	$ git checkout master
	$ cat file
	B
Switch back to the test branch and commit the change this time:
	$ git checkout test
	$ git commit -m "test branch" file
	$ cat file
	B
Now, this time when you switch back to master, you'll get what you expect:
	$ git checkout master
	$ cat file
	A

HTH, Sean

Previous: waltNext: walt
Message 7 of 15 in “My first git success”
  1. waltJan 13, 2006
  2. Linus TorvaldsJan 13, 2006
  3. Randal L. SchwartzJan 13, 2006
  4. Junio C HamanoJan 13, 2006
  5. Peter EriksenJan 13, 2006
  6. waltJan 14, 2006
  7. seanJan 14, 2006
  8. waltJan 14, 2006
  9. Randal L. SchwartzJan 14, 2006
  10. Junio C HamanoJan 14, 2006
  11. Linus TorvaldsJan 14, 2006
  12. waltJan 14, 2006
  13. Junio C HamanoJan 14, 2006
  14. Linus TorvaldsJan 14, 2006
  15. Junio C HamanoJan 15, 2006

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.