简体   繁体   English

Git会克隆,获取或推送孤儿提交吗?

[英]Will Git ever clone, fetch, or push orphan commits?

Orphan commits are created when there is no tag or branch that contains them in its graph of parent commits. 当父级提交的图形中没有包含它们的标记或分支时,会创建孤立提交。 For example, if you make a branch foo , add commits a and b , then delete the branch (ie remove the reference foo from commit b ), then both a and b will not be reachable unless you saved their hashes. 例如,如果你创建一个分支foo ,添加提交ab ,然后删除分支(即从提交b删除引用foo ),然后除非你保存它们的哈希值,否则ab都不可访问。

x-x-x-x   <- master
     \
      a-b  <- foo (reference then deleted or reset to somewhere on master)

Basic Git behavior on orphaned commits is to eventually garbage collect and delete them (I have heard the default is at least 30 days). 孤立提交的基本Git行为是最终垃圾收集和删除它们(我听说默认是至少30天)。

My question is this: 我的问题是:

Will Git ever move orphan commits from one repo to another using the git clone , git fetch , or git push commands? Git是否会使用git clonegit fetchgit push命令将orphan从一个repo提交到另一个repo?

Or does Git effectively ignore these commits for any operation that does not directly call out an orphan's hash (such as checkout or cherry-pick )? 或者Git是否有效地忽略了这些提交,因为任何操作都没有直接调用孤儿的哈希(例如checkoutcherry-pick )?

During normal Git workflow, those commits are ignored. 在正常的Git工作流程中,这些提交将被忽略。 This includes git clone , git push , and git fetch . 这包括git clonegit pushgit fetch But depending on the Git repo hosting server, you might be able to pull them back in your repo, if that is needed. 但是,根据Git repo托管服务器,如果需要,您可以将它们拉回到您的仓库中。

That is what I described in " Does github remember commit IDs? ": through the GitHub Event API , you can get back the SHA1 of a (for instance) deleted branch, and restore it that way in your own repo. 这就是我在“ github是否记得提交ID? ”中所描述的:通过GitHub事件API ,您可以返回(例如)已删除分支的SHA1,并在您自己的仓库中以这种方式恢复它。

That compensates for the fact a git reflog is generally not accessible/public on the remote side. 这弥补了git reflog在远程端通常无法访问/公开的事实。

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

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