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

Re: several quick questions

From
Linus Torvalds <torvalds@osdl.org>
Date
Feb 14, 2006, 17:05 UTC
Message-ID
<Pine.LNX.4.64.0602140845080.3691@g5.osdl.org>
In-Reply-To
<43F20532.5000609@iaglans.de>
On Tue, 14 Feb 2006, Nicolas Vilz 'niv' wrote:
Show 16 quoted lines
> 
> i wonder, how i revoke a straight forward merge of two trees... I
> actually wanted to be look like somewhere in the git-repository, where
> some branches are merged back with the master tree, but i think, that
> wasn't "cg-merge -c <tree to merge with the actual one>"...
> 
> my result was that my master tree has now the same sha1-sum as my
> development-tree and gitk visualisation differs from that what i saw in
> the git-repository. (Several Arrows headed into back into one line...)
> 
> maybe that was because i didn't do anything in my master tree in the
> meantime.
> 
> And another thing, is there no posibility to get back to some commits or
> tags? I realized you can rebranch tags... what, if i want to switch back
> to git version 1.1.6 in the git repository? Or a certain commit?
Both of these can be solved with "git reset".

Before going into any more detail on that, let's go over the other related "basic operations" too:

 - "git branch". This creates a new branch of development at an arbitrary 
   point (that defaults to "current state").
   Example:
	git branch development-trial v1.1.6
   This will create a new branch called "development-trial", which starts 
   at the v1.1.6 state. NOTE! It will _not_ check it out - your old active 
   state is left totally alone, and you still stay on whatever branch you 
   used to be on.
 - "git checkout". This switches to another branch. As a shorthand, you 
   can also choose to create the branch at the same time, but normally 
   you'd just do like this example:
	git checkout development-trial
   which will switch to the branch you just created and check that out.
 - "git reset". This will reset the current branch state to something 
   else. This is what you would use if you want to undo a commit, 
   for example: you can "reset" the current branch to before the commit 
   happened.
   NOTE! When you do this, you also have to choose what you want to do 
   about your checked-out working tree. For example, when undoing the last 
   commit, you normally want to totally undo all the working tree changes 
   too, but you might also want to just undo the commit, and leave the 
   actual changes you committed alone, so that you can re-commit them with 
   a fixed commit message, for example.
   Example:
	git reset --hard HEAD^
   this will undo the last commit (more exactly: it will select the first 
   parent of HEAD to be the new top-of-development, so if the last thing 
   you did was a merge, it will reset to the previous state). The "--hard" 
   means that you want to reset the working tree too.
   Other example:
	git reset --hard v1.1.6
   This will just reset the current branch to a particular known state (ie 
   1.1.6 in this case).
   Without the "--hard", it will _not_ change the working tree, but just 
   update the index (and branch pointer, of course) to the new state, and 
   tell you which files are "dirty" in that new state. This is great for 
   undoing just a "git commit", but leaving the tree in the state is was 
   before you committed. It's not so great if you expected to revert 
   everything, and are now confused because "git diff" shows lots of 
   changes ;)
Finally, let's go over the difference between "git fetch" and "git pull":
 - "git fetch" is what you want to do if you want to _update_ another 
   branch. For example, if you want to track what Junio is doing in his 
   git repository (assuming that was what you cloned for), doing
	git fetch origin
   will update the "origin" branch, but will _not_ touch the current 
   branch itself. This is very useful for seeing what Junio has been 
   doing, without actually affecting your own work in any way.
 - "git pull" is really just "git fetch" + "git merge". It will fetch the 
   state you asked for, and then merge that into your current branch. So 
   it's important to rmember that this actually _changes_ what you have 
   checked out and have worked on. 
   One very special case of "git pull" is when you only use the repository 
   to track another branch, and you never do any changes at all, and you 
   never switch branches around, and you always pull from the same source. 
   In that case, "git pull" will basically boil down to just a read-only 
   tracking mechanism (ie you could think of this particular usage as 
   being the git equivalent of "anoncvs" access)

The reason people may get confused is that they start out using "git pull" as a read-only tracking mechanism, and it's not necessarily obvious that "git pull" really fundamentally is a very powerful operations - much MUCH more complex and powerful than just "track that other branch". Which is why I try to make the distinction between "git fetch" and "git pull" clear.

			Linus
Previous: Nicolas Vilz 'niv'Next: Kenneth Johansson
Message 4 of 57 in “several quick questions”
  1. Nicolas Vilz 'niv'Feb 14, 2006
  2. Andreas EricssonFeb 14, 2006
  3. Nicolas Vilz 'niv'Feb 14, 2006
  4. Linus TorvaldsFeb 14, 2006
  5. Kenneth JohanssonFeb 14, 2006
  6. Andreas EricssonFeb 14, 2006
  7. Kenneth JohanssonFeb 14, 2006
  8. Linus TorvaldsFeb 14, 2006
  9. Carl WorthFeb 14, 2006
  10. Linus TorvaldsFeb 14, 2006
  11. Carl WorthFeb 14, 2006
  12. Petr BaudisFeb 14, 2006
  13. Johannes SchindelinFeb 14, 2006
  14. Junio C HamanoFeb 14, 2006
  15. Johannes SchindelinFeb 14, 2006
  16. Petr BaudisFeb 14, 2006
  17. Linus TorvaldsFeb 14, 2006
  18. Petr BaudisFeb 14, 2006
  19. Carl WorthFeb 14, 2006
  20. Junio C HamanoFeb 14, 2006
  21. New git-seek command with documentation and test.Carl Worth, Feb 23, 2006
  22. J. Bruce FieldsFeb 24, 2006
  23. git-seek: Eliminate spurious warning. Fix errant reference to git-bisect in docs.Carl Worth, Feb 24, 2006
  24. Junio C HamanoFeb 24, 2006
  25. Andreas EricssonFeb 24, 2006
  26. Junio C HamanoFeb 24, 2006
  27. Carl WorthFeb 24, 2006
  28. Johannes SchindelinFeb 24, 2006
  29. J. Bruce FieldsFeb 24, 2006
  30. Josef WeidendorferFeb 14, 2006
  31. Junio C HamanoFeb 14, 2006
  32. Josef WeidendorferFeb 14, 2006
  33. Junio C HamanoFeb 14, 2006
  34. More useful/hinting error messages in git-checkoutJosef Weidendorfer, Feb 15, 2006
  35. Andreas EricssonFeb 14, 2006
  36. Johannes SchindelinFeb 14, 2006
  37. Andreas EricssonFeb 15, 2006
  38. Junio C HamanoFeb 15, 2006
  39. Junio C HamanoFeb 15, 2006
  40. Andreas EricssonFeb 15, 2006
  41. Junio C HamanoFeb 15, 2006
  42. Petr BaudisFeb 14, 2006
  43. Carl WorthFeb 14, 2006
  44. Linus TorvaldsFeb 14, 2006
  45. Andreas EricssonFeb 14, 2006
  46. Johannes SchindelinFeb 14, 2006
  47. Carl WorthFeb 14, 2006
  48. Keith PackardFeb 14, 2006
  49. Linus TorvaldsFeb 14, 2006
  50. Keith PackardFeb 14, 2006
  51. Martin LanghoffFeb 15, 2006
  52. Keith PackardFeb 15, 2006
  53. Carl WorthFeb 15, 2006
  54. Junio C HamanoFeb 14, 2006
  55. Petr BaudisFeb 14, 2006
  56. Cogito turbo-introductionPetr Baudis, Feb 15, 2006
  57. Petr BaudisFeb 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.