Git 分支名称是 OS 依赖的?

Git branch names are OS dependent?

所以我注意到,由于 git 根据文件系统中的分支名称命名文件夹(在 refs 文件夹中,特别是 remotes),这可能会导致问题,因为文件夹名称中允许的字符是 OS依赖。

例如,您可以在 MAC OS 上创建一个分支,例如:

feature/my_special_"Splash Screen"_feature

如果我在 Windows 上获取它,它将失败并显示如下消息:

Fetch failed: fatal: Unable to create 'C:/AndroidStudioProjects/MyProject/.git/refs/remotes/origin/feature/my_special_"Splash Screen"_feature.lock': Invalid argument

由于文件名包含在 Windows 上不允许的撇号,而在 MAC OS.

上允许

当您尝试在 windows 上创建相同的分支时,git 将简单地删除撇号。

有人知道这方面的官方文档吗?另外,我们需要重命名这个分支还是有解决方法?

在“Legal Git branch names", referencing this thread:

中提到了一项非官方政策

A Git branch name can not:

  • Have a path component that begins with "."
  • Have a double dot ".."
  • Have an ASCII control character, "~", "^", ":" or SP, anywhere
  • End with a "/"
  • End with ".lock"
  • Contain a "\" (backslash)

That patch (for a better error message on invalid branch name) was not implemented,当时不包括双引号。

但是,最好避免在分支名称中使用任何特殊字符。

This comment in refs.c 仍然是最接近官方政策的:

/*
 * Try to read one refname component from the front of refname.
 * Return the length of the component found, or -1 if the component is
 * not legal.  It is legal if it is something reasonable to have under
 * ".git/refs/"; We do not like it if:
 *
 * - any path component of it begins with ".", or
 * - it has double dots "..", or
 * - it has ASCII control characters, or
 * - it has ":", "?", "[", "\", "^", "~", SP, or TAB anywhere, or
 * - it has "*" anywhere unless REFNAME_REFSPEC_PATTERN is set, or
 * - it ends with a "/", or
 * - it ends with ".lock", or
 * - it contains a "@{" portion
 */