7 ms·
One personal anecdote: In a decade of using Mercurial, I've managed to get a repository in such a confused state that I had to blow it up and start from scratc
by jcranmer 9y ago
One personal anecdote:
In a decade of using Mercurial, I've managed to get a repository in such a confused state that I had to blow it up and start from scratch just once. In the same time, I've had to do the same for git repositories at least 5 or 6 times--and I never really used git all that much. Even nowadays, where I'm more or less forcing myself to use git [1], I'm incredibly hesitant to try any sort of complex git operation because of the risk that I might lose my in-progress commits.
While the problems of git's UI is well-known, I don't think it's as appreciated that git's complexity generally discourages people from trying things out. I'm never really sure what could cause me to lose unpushed commits or uncommitted working files, especially with git's predilection for reusing the same verb to do slightly different operations for different concepts. In stark contrast, it's more difficult to get Mercurial to chew up your work without telling you [2], and it's easier to explore the command lists to see if there's something that can do what you want it to do.
[1] The repositories I'm working on involve submodules, which hg-git is exceptionally poor at supporting well. Even so, the list of git alias commands on the whiteboard is entitled "Forcing myself to use git before I rage-quit and switch to Mercurial."
[2] I have done it, though. Worst offender was discovering that hg qrefresh <list of files> causes only those file changes to be committed, and files not mentioned are decommited to working-directory-only changes... which hg qpop happily deleted without warning me, causing me to lose a large patch. That was when I put the patch queue directory in version control.
- shaan7 9y agoJust keep a copy of the `.git` dir before you try the complex operation. If you screw it up, restore it back and voila!
- sigjuice 9y agoNo. This does not safeguard any uncommitted files.
- nicoburns 9y agoLeaving any files uncommitted before a complex operation in git is a really bad idea (make a temporary commit if necessary). It's almost impossible to completely lose committed data, but pretty easy to destroy uncommitted data.
- xinsight 9y agoThis. I also do a `git diff > save.patch` if there is something uncommmited that i don't want to commit at the moment. A patch file feels more comfortable to me than git stash, as i can easily view the patch files, and reapply them with `patch -p1 < save.patch`
- lpr22 9y agoYou can show the diff with `git stash show` or also apply your patch with `git apply save.patch`
- jononor 9y agoNo. Commit your changes and mark it. For instance by creating a branch. git commit -a git checkout -b before-complex-operation ... To get back to where you were, git checkout before-complex-operation
- slavik81 9y ago> I'm never really sure what could cause me to lose unpushed commits... Effectively nothing. By default, old, unreferenced data is only garbage collected after a month. If you screw up a rebase, the old commits are still there with the same hash they always had. You just need to point the branch at them again. > ...or uncommitted working files That's fair. If I'm unsure, I just stash or commit first. Anything that's in git can be retrieved.
- __david__ 9y agoSometimes I find myself doing "git stash; git stash apply" just so I have a checkpoint of what I'm working on. That plus "git stash list -p" lets me go back through tons of non-checked in junk to find (say) that one line of debugging code that turned out to be pretty useful…
- majewsky 9y agoYou can do small temporary commits on a branch, and once you want to do an actual commit which will then be pushed, you go onto the master branch and `git merge --squash <work-branch>`.
- bloodorange 9y agoThis. Git makes using branches very easy and it is fairly quick with most operations. Once you understand what the commands are doing, you'll see that unless you do something specifically (like reset --hard with uncommitted changes, checkout a modified file etc.), you'll never lose work which has been committed in some branch or the other. I tend to just do "in-between" commits very often and rebase to reorganise the commits (reorder, squash, reword) when I hit a (micro)milestone. If your work has been committed and the repo was not just garbage collected, it is going to be easy to retrieve it from reflog even if you did something nasty with the branch and it appears that your commit has disappeared. Git is the piece of software which I find very good in terms of what it does but it does it behind the worst user-interface I have ever encountered. EDIT: minor clarifications and punctuation
- 9y ago
- popopopo 9y agowow. > I'm incredibly hesitant to try any sort of complex git operation because of the risk that I might lose my in-progress commits. correct way of learning git is every time you want to use a "complex"/dangerous commands in git, you `cd /tmp` and create a git repository there. then create some commits, branches and experiment. you will NOT lose anything, but you will learn a lot. I did and do this every time I have doubts. and with time you will understand how non-dangerous git commands are. "dangerous" part comes from the user, not the software, and it is okay. when you accidentally kick a corner of a furniture, that does not make that furniture "dangerous".
- _pmf_ 9y ago> when you accidentally kick a corner of a furniture, that does not make that furniture "dangerous". When the piece of furniture has a serrated corner that cuts deep into your toe, you'll probably reevaluate the appropriateness of your metaphor.
- popopopo 9y agooh, so if you are careless, that's furniture's fault. okay. your comment is not the best counter to my point either. PS: i have a lot of furniture with rought edges. I've learned my lesson, and furniture is not a problem anymore.
- tudorw 9y agoNo but if occasionally the furniture kicks you, then it could be improved on, pointing out flaws in the best of the best is very worthwhile, it's in that pain space that the biggest usability gains are to be had.
- lucideer 9y agoIf this is the "correct" way to learn, the problems are not with the user. A well designed ui should be learnable while being used - creating a fresh learning repo for dedicated learning for fear of losing data while using the tool in your "real" repo is the ultimate red flag in terms of usability.
- qznc 9y ago> In a decade of using Mercurial > I never really used git all that much Does not sound like a fair comparison ;)
- jhanschoo 9y agoIt's a valid comparison for his point that Mercurial is much more reliable for his workflows than git.
- larsbrinkhoff 9y agoI have used git a lot, and rarely, if ever, get it into a confused state. I have used Mercurial less, and I have found it easy to get things tangled up without a clear way out. It kinda sounds like the system you know best, is the one you can handle better regardless of whether it's git or Mercurial.
- geezerjay 9y ago> It's a valid comparison for his point that Mercurial is much more reliable for his workflows than git To me it reads as a warning that Mercurial repos are prone to being screwed up even if the user has over a decade of experience avoiding Mercurial's traps while with Git only bold inexperienced users can screw up repos in a similar matter.
- davvolun 9y agoA decade's worth of experience vs beginner-level experience could explain the issue. Not saying it does, just that it could.
- jhanschoo 9y ago> I don't think it's as appreciated that git's complexity generally discourages people from trying things out. The irony here is that the model that git internals use aren't really complex at all; it's the poor porcelain and poor naming that makes it seem complicated.
- mschaef 9y ago> I don't think it's as appreciated that git's complexity generally discourages people from trying things out. For me, at least, the underlying model actually makes it easier to try things out. As long as my work is in commits and I have refs that point to those commits, I can be pretty sure that I'm not going to lose anything. I also take a fair amount of comfort in the fact that (unlike, say, SVN), any remote actions can be deferred until I know things are correct locally. This sort of robustness in the data model makes it a bunch easier for me to forgive the (very real) usability issues in the command line UI. (And, after years of work, the command line is getting more familiar, aside from some of the more complex rebase operations.)
- AlexCoventry 9y ago> I don't think it's as appreciated that git's complexity generally discourages people from trying things out. Personally, I'm not shy about recursively copying the entire repository on disk to run potentially destructive experiments in a duplicated environment. Also, once you understand how to pull things out of the reflog, it's usually not hard to restore to a sane state.
- mschaef 9y ago> I'm not shy about recursively copying the entire repository on disk Agreed. > Also, once you understand how to pull things out of the reflog, That, and I'll also dump a git log of the last couple dozen commits into an editor buffer so that I can hang onto the commit ids. Until a GC cycle occurs, you don't lose the commits even if they aren't reachable through normal paths.
- theptip 9y ago`git reflog` gives you the historical list of SHAs that you've pointed HEAD at; even if you destroy your branch with a rebase, you can still see what commit your branch pointed to before you started the operation.
- 9y ago
- golergka 9y ago> In a decade of using Mercurial, I've managed to get a repository in such a confused state that I had to blow it up and start from scratch just once. In the same time, I've had to do the same for git repositories at least 5 or 6 times--and I never really used git all that much. I have used git for a long time, but never arrived at such a state, apart from when I was converting existing SVN repo to git (where starting the process anew after 10 minutes of experimenting was faster than restoring refs). How did you manage to do it?
- mikestew 9y agoHow did you manage to do it Same way everyone else manages it, including myself: abject ignorance. You and I (as a now more experienced git user) know that it is extremely unlikely to actually be in a state where blowing away the repository is necessary. Like you, I can’t think of how one would pull that off. That’s why I tell less experienced users “if you’ve committed, even just locally, you can’t lose your work without really trying. If you get in trouble, don’t use the ‘-f’ switch, and come get me, we’ll get it sorted out. But that was not me nine years ago as I blew away the repository again because I got in a confused state (me, not git). And be honest, that was you nine years ago, too, before you wrapped your head around git.
- tomxor 9y agoI'd like to think I know git pretty well... I understand the internals, i've written cli tools that utilise all the plumbing commands, I understand the different types of objects merkel trees, and various form of references. Yet, once when I had a power failure by chance the second I fired the commit trigger... I was pretty hopeless at trying to clear up the mess of objects it exploded everywhere, I couldn't be bothered and just re-cloned the blasted thing, hope it never happens to me again.
- rbehrends 9y agoI very much doubt that this is a Git issue, but suspect that it is instead a file system/OS/hardware issue. The problem is that operating systems generally offer only very limited guarantees about the atomicity of the bits actually being physically stored on a device (at least guarantees that can be used with reasonable efficiency). It should not normally be a problem, but a power failure just at the wrong time seems the prime suspect to me; there's nothing in Git's logic that should normally allow for such a problem. See, for example, the "Failure to sync" section of SQLite's page on "How to Corrupt an SQLite Database". [1] https://www.sqlite.org/howtocorrupt.html#_failure_to_sync https://www.sqlite.org/howtocorrupt.html#_failure_to_sync
- dboreham 9y agoUm..a mission critical data store shouldn't be affected by a "power failure at just the wrong time".
- rbehrends 9y agoSure, but the same things could happen to (say) a relational database under the same circumstances. There's nothing that you can do if (say) the hardware lies to you about having written bits to disk or reorders writes. I was citing the SQLite page for a reason. You can only work with the tools that the OS gives you.
- flukus 9y agoGit is not a mission critical data store. Corruption should cause a bad day, not a disaster.
- ngoldbaum 9y agoIn response to [2], these days MQ is deprecated and there's a big push to get people to use evolve, which avoids this mess and is much safer.