Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Git never delete any information?

I have read this post: http://jenkins-ci.org/content/summary-report-git-repository-disruption-incident-nov-10th

which describes an incident where a user accidentally triggered a git push --force from an outdated state of the repository.

Now of course this requires some clean up to restore the original state branches. But since Git never deletes information as I understand this clean up process is always possible.

So even though you rebase, push --force (and other operations that might rewrite the history) the original commits are still there they just needs to be found right?

In short are the any (destructive) operation in git that actually deletes data?

like image 308
u123 Avatar asked Oct 19 '14 08:10

u123


People also ask

Does git ever delete anything?

Yes you can. As an example, try git reflog .

Does git delete branch delete commits?

What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.

Does deleting a branch delete files?

Like all deletes in svn, the branch is never really deleted, it's just removed from the current tree.

What happens when you delete a remote branch git?

Note that deleting the remote branch X from the command line using a git push will also remove the local remote-tracking branch origin/X , so it is not necessary to prune the obsolete remote-tracking branch with git fetch --prune or git fetch -p . However, it wouldn't hurt if you did it anyway.


1 Answers

Commits that are not reachable via any reference will eventually be deleted, which includes the reflog. The default time period for this to happen is pretty conservative. There are several options you can use to adjust this via git config See below for some of the specific options.

A lot of people (myself included), would suggest that you setup your receive hooks to deny non-fast-forward merges, which would largely make this issue moot (on the server, individuals could still lose unpushed local work).

gc.auto
When there are approximately more than this many loose objects in the repository, git gc --auto will pack them. Some Porcelain commands use this command to perform a light-weight garbage collection from time to time. The default value is 6700. Setting this to 0 disables it.
gc.pruneexpire
When git gc is run, it will call prune --expire 2.weeks.ago. Override the grace period with this config variable. The value "now" may be used to disable this grace period and always prune unreachable objects immediately.

gc.reflogexpire
gc.<pattern>.reflogexpire
git reflog expire removes reflog entries older than this time; defaults to 90 days. With "<pattern>" (e.g. "refs/stash") in the middle the setting applies only to the refs that match the <pattern>.

gc.reflogexpireunreachable
gc.<ref>.reflogexpireunreachable
git reflog expire removes reflog entries older than this time and are not reachable from the current tip; defaults to 30 days. With "<pattern>" (e.g. "refs/stash") in the middle, the setting applies only to the refs that match the <pattern>.
like image 122
Andrew C Avatar answered Nov 12 '22 11:11

Andrew C