Git branch name - case sensitive or insensitive?

前端 未结 2 1601
北恋
北恋 2020-12-01 18:03

I am a new git user and recently been handed with an out of date git repository to look after.

This is the original state ( output by git show-branch):



        
相关标签:
2条回答
  • 2020-12-01 18:28

    So I went ahead and create new branch (git branch DEV)

    You created a new branch DEV when you were on the branch dev. So DEV and dev are two branches that point to the same commit. After you renamed DEV to DV, now DV and dev are two branches that point to the same commit.

    Everything is just fine. If you don't want DV to bother you, you could just run git branch -d DV to remove it. If you indeed want to make a new branch, better to follow some naming rule which cannot confuse you and others.

    I never used git show-branch. git log --oneline --all --graph --decorate=full draws a clear log graph.

    0 讨论(0)
  • 2020-12-01 18:30

    Answering just the question in the subject line, without addressing anything about git show-branch (like ElpieKay, I never actually use git show-branch; it seems mainly mis-informative):

    Git branch names—and tag names, and all other reference names, as Git calls them—were originally intended to be case-sensitive.

    This all works perfectly on Linux / Unix machines, where Git's code is case-sensitive to start with. When Git stores branch names in the file system as file names (which it only does sometimes), the file system is also case-sensitive.1

    It sometimes fails on Windows and some MacOS systems. Specifically, it fails when Git stores references in individual files, whose names are derived from the reference name, and those file names are case-insensitive (e.g., case-preserving, but fold case during name-matching; or even converting everything to uppercase-only, as in the really old FAT 8.3 format, but we can hope no modern file system does this).

    As noted above, Git does not always store reference names as file names. In fact, on initial clone, all the names are in a single file called .git/packed-refs,2 so at this point they are case sensitive. But they become "unpacked" over time,3 and then on some systems they become case-folding.

    Because it sometimes fails on some systems, it's generally best to avoid using multiple reference names that differ only in case.


    1Of course, on modern Unix/Linux systems, you can now get access to case-preserving-but-case-insensitive file systems, and Windows and MacOS can now be told not to do case-folding for some file systems. (But if you change from the defaults, expect software that is intended for your box to fail, because it will. Things like Photoshop internally try to use files named foo and FOO and expect this to refer to the same file!)

    2This packed-references file has been around for quite a while, but not forever, and very early versions of Git may not use it. Internally, Git is acquiring a new "pluggable reference name interface" and future versions of Git might use neither this file, nor individual per-reference files.

    3In general, creating or updating a reference causes an unpacked reference file to come into existence. Running git pack-refs --all will replace unpacked references with packed ones, restoring full case-sensitivity. Without --all, git pack-refs only packs already-packed references, which is largely a useless mode of operation (it was intended for a case that is no longer used).

    0 讨论(0)
提交回复
热议问题