Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long does git keep out-of-branch commits?

Tags:

git

Assume I create a branch in my local repository named feature1 based on master and add one or two commits. Then I switch back to master and decide that feature1 is not going to make it and delete the branch.

I assume that a branch is basically a "pointer" to a particular commit object.

Now on to the actual questions.

  1. Is the assumption above correct, perhaps in some simplified sense?
  2. For how long do the commit objects still exist on the filesystem (so that I can later do git checkout SHA1-HERE)? Is there some kind of "retention policy" that would remove commits which are not part of any existing branch history or tag (not sure if using correct terminology here...) ?
  3. Would any of the above be dependent on the git server's implementation (gitosis, github, etc...)?
  4. If the objects are kept around forever and are not auto-cleaned after some time/event, would it imply that setting git's receive.denyNonFastForwards as a measure to prevent data loss is meaningless?

Reason for this question: I am currently working on a project that has receive.denyNonFastForwards enforced on the basis that it avoids losing any committed work (I suspect receive.denyDeletes is also enforced). I want to make sure there is no better way to preserve commited but unmerged work and also be able to clean up old branches to avoid clutter.

like image 895
Robert Rossmann Avatar asked Dec 10 '14 09:12

Robert Rossmann


People also ask

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 Git ever delete commits?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

How far back does Git Reflog go?

By default, the reflog expiration date is set to 90 days. An expire time can be specified by passing a command line argument --expire=time to git reflog expire or by setting a git configuration name of gc.

Does GitHub keep Reflog?

Reflogs keep track of when git references in the local repository were modified. A separate reflog is kept for the git stash, in addition to branch tip reflogs. Reflogs are kept in folders under the. git directory of the local repository.


1 Answers

The default s 90 days:

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>.

So:

  1. Yes
  2. 90 days
  3. no (you actually can contact GitHub support to ask them and restore a deleted pushed branch)
  4. "preserve commited but unmerged": you can push it on a dedicated dev branch or to a dedicated upstream repo (just for you)
like image 86
VonC Avatar answered Sep 21 '22 22:09

VonC