3

Does Git record the history of pushes to a remote anywhere?

I noticed that we're able to view the push history of our Git repositories in Microsoft VSTS and the associated commits with each push. It even displays old, obsolete commits which should not exist anymore due to later force pushes that rewrote the commit history. Is this additional info specially provided by VSTS and not built into Git?

derrick
  • 177
  • 1
  • 1
  • 7
  • Can't it be some tags automated via a `pre-push` hook? Tagged commits are indeed protected against garbage collection and history rewrites. Worth checking in ref/tags maybe? And in this case it could make sense that VSTS just kept an internal reference to the tag itself – Romain Valeri Aug 08 '18 at 22:39
  • https://stackoverflow.com/questions/44161548/how-to-remove-dangling-commits-in-remote-git-repository-like-vsts – cmbuckley Aug 08 '18 at 22:40
  • 2
    Git itself does not (record push operations—technically, as far as Git itself is concerned, these are just `git receive-pack` invocations, run via ssh or a web server or whatever). Various add-ons might. – torek Aug 08 '18 at 22:47
  • @ohitsderrick, What about this issue in your side? Do you resolve it? – Jack Zhai Aug 23 '18 at 15:44
  • @JackZhai-MSFT I think the answer by Daniel below about `git gc` not being implemented explains what I'm seeing. I read [this answer](https://stackoverflow.com/a/44237134/5728464) from a different thread that running `git gc` on a local clone, deleting the entire remote repo on VSTS, then pushing back the recently cleaned local one would be the only way to clean obsolete objects. – derrick Sep 13 '18 at 18:21

2 Answers2

2

Not sure if I totally got your point, if you are talking about the remote side push history in below screenshot.

enter image description here

For local repos, you could take a look at this thread:

Actually, when you execute git reflog expire --expire=now --all and git gc --prune=now, the danglind commits were removed. You can double check by git fsck --full. If the output doesn’t show commits, that means there has no dangling commits.

However you could not perform any git command for remote git repo, this should cause by this as Daniel also mentioned above:

We rolled out commit reachability bitmap indexes to VSTS and removed the clone cheat mentioned below. Cloning will no longer download unreachable objects!. We still don't have true object-level git gc on the server yet, but clone sizes will be smaller now.

TFS on-prem will get these changes in v.Next (not in any TFS 2017 updates, but the next major release).

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
1

It's because VSTS does not implement git gc for its repos. Even if the commits are no longer referenced (such as due to a force push), they stick around.

Ref: https://blogs.msdn.microsoft.com/congyiw/2015/12/14/why-does-cloning-from-vsts-return-old-unreferenced-objects/

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120