Why Isn't There A Git Clone Specific Commit Option?

前端 未结 4 2030
一向
一向 2020-12-02 17:25

In light of a recent question on SO, I am wondering why isn\'t there an option in git clone such that the HEAD pointer of the newly created branch will point to

4条回答
  •  醉酒成梦
    2020-12-02 17:55

    As the other answers say, this is typically not much of an issue, but they don't say why you can't clone a specific commit. The answer is security.

    If you accidentally push confidential information, and then force-push a fixed history, the commits with the confidential information will still be stored on the server, until the server's Git's garbage collector finds it is no longer needed. If the hash is known (it might for example be available in logs), a malicious user might request the specific commit that shouldn't have been pushed, even if you were able to verify that when you force-pushed the fixed history, nobody had fetched those commits yet.

    Making sure you can only clone from refs makes sure that only "reachable" commits will be sent to the clients.

提交回复
热议问题