Do dangling git add blobs get pushed to master repository?

240 views Asked by At

We can recover files, which were once added (but not committed) and later removed using git reset --hard. See Recovering added file after doing git reset --hard HEAD^

When we push in our changes to some upstream repository, Are these blobs also pushed in?

Context: While doing any development, I occasionally do a git add on files changed, but don't commit them. This one time, I did a git add with some critical api credentials, and I was wondering if they could be recovered from the logs if I were to ever open-source the repo/gem.

2

There are 2 answers

0
knittl On BEST ANSWER

No, blobs that were not committed (or pushed explicitely) are never transmitted over the wire.

If you added files and never committed, they should get removed with the next call to git gc. If you however committed them, and then removed the commit again (e.g. through git rebase or git reset), they will not be collected because they are reachable through Git's reflog. But the reflog is a local mechanism and will not be published with git push.

0
kostix On

Git only ever transfers objects linked with each other, starting with some commit object.

Since it's only possible to push commit objects (no matter if you name them directly using their SHA-1 names or indirectly through brahch or tag names), Git transfers commits, and each commit refers to a single tree object, representing the root of the repository, which itself refers to blobs (representing the contents of individual files) and other trees.

So only objects reachable from the root tree object are transferred along with the commit which refers to that tree object; this is done for each commit which gets transferred to the remote repository. Dangling objects are by definition not reachable so they are not transferred.