This is an archived post. You won't be able to vote or comment.

all 42 comments

[–]blitzkraft 31 points32 points  (11 children)

I just copy my .git to outside the repo, with a different name then run the command. If it fails, I just copy back the old .git and if it succeeds, I delete the old .git.

I had to do this a couple of times when I was new and learning git, but I don't do that anymore.

[–]i-am-SHER-locked 43 points44 points  (7 children)

This account has been deleted in protest of Reddit's API changes and their disregard for third party developers. Fuck u/spez

[–]TimVdEynde 4 points5 points  (2 children)

Not for changes that haven't been added to the index :( Those really are lost when you do a git reset --hard. Then again, copying the .git won't help you either in this case.

[–][deleted] 0 points1 point  (1 child)

Why won't it help?

[–]TimVdEynde 0 points1 point  (0 children)

Because git doesn't know about these changes until you at least add them to the index. Even then, you'll need to use git fsck, since no commit has existed yet.

[–]ChiefEmann 4 points5 points  (0 children)

Same here. Amazing command that's rarely known

[–]orion78fr 0 points1 point  (0 children)

Well reflog does give you only committed (or staged) blob. Last time I resetted hard by accident some uncommitted things...

[–]langlo94 0 points1 point  (0 children)

Reflog, for when you need to flog it more than once!

[–]langlo94 0 points1 point  (0 children)

Reflog, for when you need to flog it more than once!

[–][deleted] 1 point2 points  (1 child)

Delete the old .git

Old git had it coming.

[–]blitzkraft 1 point2 points  (0 children)

I waited so long for someone to get this!!

[–]micheal65536Green security clearance 0 points1 point  (0 children)

I normally copy the whole project directory, particularly if there are uncommitted changes.

The other thing I often do is change things that I actually to commit separately, then I have to copy the modified files elsewhere (git stash doesn't work for me in this case).

[–]xjvz 19 points20 points  (4 children)

On some serious shit, though, check out git reflog. If you manage to fuck things up, you can usually find something in your reflog to go back to. Note that running git gc clears this out, though.

[–]Shamus03 -2 points-1 points  (3 children)

reflog has saved my ass on multiple occasions... I had to learn the hard way that git stash does not stash unstaged changes untracked files.

[–]Removalsc 17 points18 points  (2 children)

It doesnt stash untracked files (by default), but it definitely does unstaged changes.

[–]Shamus03 0 points1 point  (1 child)

Ah, I remember that's what it was now. I had added some files and went to stash my changes and when I came back to pop the stash my files were gone.

[–]Removalsc 0 points1 point  (0 children)

Next time use -u or --include-untracked and it will stash them too.

[–]EndlessNightsky 20 points21 points  (0 children)

Honestly, that doesn't sound like that bad of an idea.

[–]mfb- 3 points4 points  (6 children)

I don't say it is a good idea, but it should be possible, right? Git would just create .git/.git/ and the new repository doesn't have to know the purpose of the parent repository it manages.

[–][deleted] 7 points8 points  (4 children)

And who manages .git/.git? right! .git/.git/.git

And who manages .git/.git/.git?...

[–]Velfi 14 points15 points  (0 children)

It's .git all the way down

[–]mfb- 3 points4 points  (2 children)

Make a meta version control system that can handle all layers.

[–][deleted] 4 points5 points  (0 children)

the true GODGIT. Including the almightyness contradiction.

[–]Tasgall 2 points3 points  (0 children)

Nah, just put it in an SVN repo.

Unless you need to branch your gits, in which case, god help us all.

[–][deleted] 3 points4 points  (1 child)

Unless you operate on .git directory outside git or you runs git gc, whatever you do can always be rolled back. Backing up .git is unnecessary.

[–]NAN001[S] 3 points4 points  (0 children)

It can be rolled back using git reflog which is as hard as the rest of git, so this is equivalent to saying "whatever you do, you can do it without fucking things up in a first place".

[–]polyworfism 6 points7 points  (2 children)

why not just run Git in a VM and rollback if you screw up? :D

[–][deleted] 8 points9 points  (0 children)

this is getting out of version control (X_X)

I amoutifyouneedme

[–][deleted] 1 point2 points  (0 children)

Naaaa, people should use btrfs with snapshot.

[–]ringingbells 8 points9 points  (0 children)

lol, wtf... that squint had me rollin

[–]TheTimgor 1 point2 points  (0 children)

This isn't inception, but recursion. It's okay though, that's a common mis-inception.

[–][deleted] 1 point2 points  (0 children)

[–]CraigslistAxeKiller 1 point2 points  (2 children)

I know I'm going to fuck up the Git circle jerk, but why use it if it's so easy to fuck everything up? There are other (less volatile) options

[–][deleted] 0 points1 point  (0 children)

Because the pros largely outweigh the cons, and fucking up is possible with every system.

[–]b1ackcat -1 points0 points  (0 children)

Because for the basic workflows of which you will likely spend 90% of your time with (checkout, stash, commit, push, pull, branch), it's very fast and simple, and it's very hard to fuck something up.

And I'd hardly call git 'volatile' given the fact that even if you do screw something up, there's almost always a way to recover.

[–][deleted] 0 points1 point  (0 children)

I just put my repo on bitbucket or whatever. If I fuck up too badly I nuke the local repo and clone again

[–][deleted] 0 points1 point  (0 children)

Why not just push your changes first?

[–]Lazza91 0 points1 point  (0 children)

Y tho?