如何控制文件在 GitHub 主题中的出现顺序

有没有办法控制文件在要点中出现的顺序?看起来不像是按字母顺序或者时间顺序排列的。我想让一个 README.md 作为 多文件的要点中的第一个文件出现,但是无论如何“删除”一个文件并重新添加它似乎都不会改变任何东西。

这些文件是否有我没有看到的顺序,或者 GitHub 是否维护一个内部文件类型优先级列表?

22624 次浏览

Since at least 2018, the order is alphabetical, with periods and numbers coming before letters.

That is, as mentioned in Andrew D.Bond's answer:

  1. $
  2. . (dot)
  3. Numbers
  4. Leading space (although the space doesn't appear after saving, the sort order is still updated)
    (although bis, in Sept. 2020, IvanaGyro adds in the comments leading spaces will not affect the order any more)
  5. _ (underscore)
  6. Letters (case insensitive)

Around 2013-2014 a different order was used. See Andrew D. Bond's answer for more.

As mentioned by @VonC in his answer, the order is asciibetical. Quick solution would be to prefix all files with numbers indicating the order in which you wish the files to appear, example 0_, 1_, 2_, ... 9_. Note, this solution will not work beyond 9 files as 10_ will appear before 2_. In that case, two digits need to be used 00_, 01_, 02_, ..., 09_, 10_, 11_, ... This can be generalized to any number of digits in the number of files. Although, it seems less likely, to me, that more more than 10 files to be shared in a gist.

They are ordered automatically by name, following the ASCII table.

Unfortunatly, right now, it is not possible to order them by dragging, but there is a trick. You can control the order by adding one or more spaces before the name. The space will not be shown after editing, but the order will change.

E.g: lets say we have 3 files with the automatic order:

  • AFile.java
  • Readme.md
  • SomeFile.txt

We can invert the order by putting spaces like this:

  • (space)(space)SomeFile.txt
  • (space)Readme.md
  • AFile.txt

Updating my answer from an earlier year with additional testing I did just now:

Github automatically sorts files in a gist according to:

  1. #
  2. $
  3. . (period)
  4. Numbers
  5. _ (underscore)
  6. Letters (case insensitive)

Leading spaces are dropped.

If additional characters' sort order is discovered, feel free to edit this answer.

(Added this answer because even after I improved another answer to this question last year, I still couldn't find the sort order of special characters anywhere.)