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

Re: Git in a Nutshell guide

From
Benoit Sigoure <tsuna@lrde.epita.fr>
Date
Nov 19, 2007, 16:57 UTC
Message-ID
<E983072E-E9FD-499E-A418-B630A275C4F3@lrde.epita.fr>
In-Reply-To
<8c5c35580711190845s71a4880ek4ab28170d277e0e6@mail.gmail.com>
On Nov 19, 2007, at 5:45 PM, Lars Hjemli wrote:
Show 10 quoted lines
> On Nov 19, 2007 2:05 PM, Jonas Juselius  
> <jonas.juselius@chem.uit.no> wrote:
> Also, I think you might scare users away from 'git reset':
>
>   git reset resets the branch to a specified state invisibly and
>   without possibility to go back. Ever. Your call.
>
> That's not true, since any "modern" git has reflogs enabled. If you do
> 'git reset --hard HEAD^^^' and then realize it was a mistake you can
> just 'git reset --hard HEAD@{1}'

Yes, I've always been very scared of git-reset until I had a somewhat better understanding of Git internals. In fact the only danger of `git reset --hard' is that you loose dirty changes (not yet in the index) and staged changes (in the index). git-reset will never, ever delete objects from your repo. Thus, you can perfectly well remember the current revision sha1 (let's call it `A') and then git reset -- hard HEAD~42 and then git reset --hard A. In between the two Git commands, it's possible that all the objects of the history from HEAD~42..A be unreachable. Nothing wrong with this, it just that if run, say, git gc --prune (note the --prune) you will loose them.

Understanding this is very important because ``error humanum est'', and people happen to screw up their hard work and they don't realize that they can go back without even knowing what the hell the reflog is or how to use it (I personally don't know -- but I'd like to, give me pointers please :D). For instance, I once rebased a dozen of commits on a given branch and I realised that I completely screwed my nice patch series by collapsing changes, introducing changes at the wrong revision etc. I could start over again by simply doing a git reset --hard <HEAD_sha1_before_rebase>.

Cheers,
-- 
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory
Previous: Jonas JuseliusNext: Lars Hjemli
Message 24 of 40 in “Git in a Nutshell guide”
  1. Jonas JuseliusNov 19, 2007
  2. Jakub NarebskiNov 19, 2007
  3. Jonas JuseliusNov 19, 2007
  4. David KågedalNov 22, 2007
  5. Jakub NarebskiNov 23, 2007
  6. Brian DowningNov 19, 2007
  7. Brian DowningNov 19, 2007
  8. Nicolas PitreNov 19, 2007
  9. Jakub NarebskiNov 19, 2007
  10. Jonas JuseliusNov 19, 2007
  11. Benoit SigoureNov 19, 2007
  12. Daniel BarkalowNov 19, 2007
  13. Jonas JuseliusNov 20, 2007
  14. Jakub NarebskiNov 20, 2007
  15. Jan HudecNov 21, 2007
  16. Jakub NarebskiNov 21, 2007
  17. jhud7196@artax.karlin.mff.cuni.czNov 22, 2007
  18. Jonas JuseliusNov 22, 2007
  19. Jonathan del StrotherNov 22, 2007
  20. Johannes SchindelinNov 22, 2007
  21. jhud7196@artax.karlin.mff.cuni.czNov 22, 2007
  22. Lars HjemliNov 19, 2007
  23. Jonas JuseliusNov 19, 2007
  24. Benoit SigoureNov 19, 2007
  25. Lars HjemliNov 19, 2007
  26. Benoit SigoureNov 19, 2007
  27. J. Bruce FieldsNov 19, 2007
  28. Matthieu MoyNov 19, 2007
  29. Doc fix for git-reflog: mention @{...} syntax, and <ref> in synopsys.Matthieu Moy, Nov 19, 2007
  30. Junio C HamanoNov 19, 2007
  31. Doc fix for git-reflog: mention @{...} syntax, and <ref> in synopsys.Matthieu Moy, Nov 19, 2007
  32. Matthieu MoyNov 19, 2007
  33. Benoit SigoureNov 19, 2007
  34. Matthieu MoyNov 19, 2007
  35. Benoit SigoureNov 19, 2007
  36. J. Bruce FieldsNov 19, 2007
  37. Junio C HamanoNov 19, 2007
  38. Matthieu MoyNov 19, 2007
  39. Junio C HamanoNov 19, 2007
  40. Matthieu MoyNov 19, 2007

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.