简体   繁体   English

悬挂git add blob是否被推送到主存储库?

[英]Do dangling git add blobs get pushed to master repository?

We can recover files, which were once added (but not committed) and later removed using git reset --hard. 我们可以恢复曾经添加(但未提交)并随后使用git reset --hard删除的文件。 See Recovering added file after doing git reset --hard HEAD^ 请参阅在执行git reset --hard HEAD之后恢复添加的文件

When we push in our changes to some upstream repository, Are these blobs also pushed in? 当我们将更改推送到某些上游存储库时,是否还会推送这些Blob?

Context: While doing any development, I occasionally do a git add on files changed, but don't commit them. 上下文:在进行任何开发时,我偶尔会对更改过的文件进行git add,但不要提交它们。 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. 这次,我用一些关键的api凭证进行了git add,我想知道是否可以从日志中恢复它们,如果我要开源repo / gem。

No, blobs that were not committed (or pushed explicitely) are never transmitted over the wire. 不,未提交(或明确推送)的Blob永远不会通过电线传输。

If you added files and never committed, they should get removed with the next call to git gc . 如果您添加了文件但从未提交过,则应在下次调用git gc将其删除。 If you however committed them, and then removed the commit again (eg through git rebase or git reset), they will not be collected because they are reachable through Git's reflog. 但是,如果您提交了它们,然后再次删除了提交(例如,通过git rebase或git reset),则将不会收集它们,因为可以通过Git的reflog来访问它们。 But the reflog is a local mechanism and will not be published with git push . 但是reflog是本地机制,不会通过git push发布。

Git only ever transfers objects linked with each other, starting with some commit object. 从某些提交对象开始,Git只传输彼此链接的对象。

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. 由于只能推送提交对象(无论您是使用其SHA-1名称直接命名还是通过Brahch或标记名间接命名),Git都会传输提交,并且每个提交都引用一个对象,表示对象的根存储库,它本身是指Blob (代表单个文件的内容)和其他树。

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. 根据定义,悬挂的对象是不可到达的,因此它们不会被传输。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM