What are the consequences of using receive.denyCurrentBranch in Git?

后端 未结 6 1196
借酒劲吻你
借酒劲吻你 2020-11-29 20:54

I have a Git repository. I have cloned the repository and can commit my local changes. When I push my changes to the server it works.

As soon as I create a branch, I

6条回答
  •  粉色の甜心
    2020-11-29 21:44

    Autopsy of the Problem

    When a branch is checked out, committing will add a new commit with the current branch's head as its parent and move the branch's head to be that new commit.

    So

    A ← B
        ↑
    [HEAD,branch1]
    

    becomes

    A ← B ← C
            ↑
        [HEAD,branch1]
    

    But if someone could push to that branch inbetween, the user would get itself in what git calls detached head mode:

    A ← B ← X
        ↑   ↑
    [HEAD] [branch1]
    

    Now the user is not in branch1 anymore, without having explicitly asked to check out another branch. Worse, the user is now outside any branch, and any new commit will just be dangling:

         [HEAD]
            ↓
            C
          ↙
    A ← B ← X
            ↑
           [branch1]
    

    Hypothetically, if at this point, the user checks out another branch, then this dangling commit becomes fair game for Git's garbage collector.

提交回复
热议问题