News for hackers. Stuff that matters.
Re:Is Git Irreplaceable? (2019) by jorvi on Tuesday January 07, 2020 @09:34AM (#21980224)
> make sure you commit

This is not absolute gospel. If you screw up a rebase and commit, whatever you removed in the rebase is simply gone.

Re:Is Git Irreplaceable? (2019) by jerf on Tuesday January 07, 2020 @09:52AM (#21980401)
Are you saying that with knowledge of what "git reflog" is? I suspect not. I'd really need to see a sequence of commands that removes committed state from the repo to buy this. If you try to produce it, bear in mind the first thing I'm going to do is run "git reflog" on the result, so if you find your committed state is still there, then I'm going to say it's still saved.

(That's not a git thing. I don't really even want some sort of hypothetical source control system that literally tracks every change I make. It's technically conceivable and should be practical to what would at least be considered a "medium sized" project in the git world, but I'd just be buried in the literally thousands of "commits" I'd be producing an hour. Failing that sort of feature, a source control system can't help but "lose" things not actually put into it.)

Re:Is Git Irreplaceable? (2019) by mannykannot on Tuesday January 07, 2020 @10:57AM (#21981133)
As I am not familiar with the details of reflog (I don't recall ever using it) I took a look at the article. I wasn't long until I reached what looks like a caveat: "This command has to be executed in the repository that had the lost branch. If you consider the remote repository situation, then you have to execute the reflog command on the developer’s machine who had the branch." Joe, who works on another continent, quit last week and his computer was a VM...

OK, so we have backups of his VM and we can recreate a clone of it, but will that be satisfactory? Are there any issues with hardware MAC addresses or CPU ids? How far down the rabbit hole of git minutiae do you have to go before you are confident that you can do all basic source-control operations safely?

Re:Is Git Irreplaceable? (2019) by jerf on Tuesday January 07, 2020 @12:11PM (#21981951)
No source control system can solve the problem of not having things it was never given.
Re:Is Git Irreplaceable? (2019) by gallier2 on Tuesday January 07, 2020 @12:59PM (#21982586)
git log --reflog --all

is the more important imo than

git reflog

Re:Is Git Irreplaceable? (2019) by RichardCA on Tuesday January 07, 2020 @10:58AM (#21981148)
The main thing that people fail to understand is that commits are immutable and the overall commit graph is immutable (with the caveat that pathways in the graph that don't end in a branch head are subject to garbage collection).

A rebase does not destroy information. It creates new commits and moves the branch head to a different spot on the graph.

The reason git is seen as painful is because you can't claim expertise until you develop the ability to form a mental map of the graph. But once you do this the lights turn on and everything starts to make sense.

This is why the mantra "commit early and often" still holds. The more experienced git user will tell the newer people this, so when they come with a mess it will always be recoverable.

Re:Is Git Irreplaceable? (2019) by fulafel on Tuesday January 07, 2020 @11:24AM (#21981413)
That GC a pretty big caveat! Combined with the fact that unreferenced objects are never pushed.

reflog is like undelete in filesystems, it's a probabilistic accident recovery mechanism for an individual computer (repo checkout in this case) that you can try to use if you don't have backups.

Re:Is Git Irreplaceable? (2019) by vvillena on Tuesday January 07, 2020 @12:59PM (#21982583)
In any case, git garbage collection isn't a common phenomenon. It usually triggers every few weeks, even in repos with high activity. The chance of hitting a GC that deletes an untracked commit you need is extremely small.
Re:Is Git Irreplaceable? (2019) by chousuke on Tuesday January 07, 2020 @09:46AM (#21980329)
How would it be gone? You can't rebase onto a dirty working directory so you can't blow away uncommitted changes accidentally and any state prior to and during the rebase is always recoverable via the reflog.

It takes trying to do anything that's not easily recoverable as long as you commit before you start messing around and don't rm -rf .git.

Re:Is Git Irreplaceable? (2019) by rohansingh on Tuesday January 07, 2020 @09:52AM (#21980393)
It's definitely not gone. Just `git checkout ORIG_HEAD` and you'll be back to whatever the tree was before you rebased.
Re:Is Git Irreplaceable? (2019) by gallier2 on Tuesday January 07, 2020 @12:58PM (#21982570)
NO. Nothing is gone after commit. You just don't see it.

Make a git log --reflog --all and you will see all the commits you made (or rebase made) in the last 3 months.

You can than rescucitate an old branch by simply putting a branch name on it with git branch newname <old sha1>

Re:Is Git Irreplaceable? (2019) by sergiosgc on Tuesday January 07, 2020 @09:56AM (#21980441)
It won't be gone until you actively prune dangling commits. The commit may not be reachable from the HEADs of existing branches, but go through the reflog and your commits will be there. You can then create a branch to make the commit reachable.
Re:Is Git Irreplaceable? (2019) by vrsfvwae5tbh on Tuesday January 07, 2020 @09:45AM (#21980321)
Does this not show up in the reflog?