Is there a way to represent a directory tree in a Github README.md?

后端 未结 14 1760
庸人自扰
庸人自扰 2020-12-22 17:03

In my Githubs repos documentation I want to represent a directory tree structure like this:

\"enter

14条回答
  •  有刺的猬
    2020-12-22 17:53

    Here is a useful git alias that works for me.

    git config --global alias.tree '! git ls-tree --full-name --name-only -t -r HEAD | sed -e "s/[^-][^\/]*\//   |/g" -e "s/|\([^ ]\)/|-- \1/"'
    

    Here is the output of git tree

    jonavon@XPS13:~/projects/roman-numerals$ git tree
    .gitignore
    pom.xml
    src
       |-- main
       |   |-- java
       |   |   |-- com
       |   |   |   |-- foxguardsolutions
       |   |   |   |   |-- jonavon
       |   |   |   |   |   |-- AbstractFile.java
       |   |   |   |   |   |-- roman
       |   |   |   |   |   |   |-- Main.java
       |   |   |   |   |   |   |-- Numeral.java
       |   |   |   |   |   |   |-- RomanNumberInputFile.java
       |   |   |   |   |   |   |-- RomanNumeralToDecimalEvaluator.java
       |-- test
       |   |-- java
       |   |   |-- com
       |   |   |   |-- foxguardsolutions
       |   |   |   |   |-- jonavon
       |   |   |   |   |   |-- roman
       |   |   |   |   |   |   |-- InterpretSteps.java
       |   |   |   |   |   |   |-- RunCukesTest.java
       |   |-- resources
       |   |   |-- com
       |   |   |   |-- foxguardsolutions
       |   |   |   |   |-- jonavon
       |   |   |   |   |   |-- roman
       |   |   |   |   |   |   |-- Interpret.feature
       |   |   |-- sample-input.txt
    

    The comparable tree command

    jonavon@XPS13:~/projects/roman-numerals$ tree -n
    .
    ├── pom.xml
    ├── src
    │   ├── main
    │   │   └── java
    │   │       └── com
    │   │           └── foxguardsolutions
    │   │               └── jonavon
    │   │                   ├── AbstractFile.java
    │   │                   └── roman
    │   │                       ├── Main.java
    │   │                       ├── Numeral.java
    │   │                       ├── RomanNumberInputFile.java
    │   │                       └── RomanNumeralToDecimalEvaluator.java
    │   └── test
    │       ├── java
    │       │   └── com
    │       │       └── foxguardsolutions
    │       │           └── jonavon
    │       │               └── roman
    │       │                   ├── InterpretSteps.java
    │       │                   └── RunCukesTest.java
    │       └── resources
    │           ├── com
    │           │   └── foxguardsolutions
    │           │       └── jonavon
    │           │           └── roman
    │           │               └── Interpret.feature
    │           └── sample-input.txt
    └── target
        ├── classes
        │   └── com
        │       └── foxguardsolutions
        │           └── jonavon
        │               ├── AbstractFile.class
        │               └── roman
        │                   ├── Main.class
        │                   ├── Numeral.class
        │                   ├── RomanNumberInputFile.class
        │                   └── RomanNumeralToDecimalEvaluator.class
        ├── generated-sources
        │   └── annotations
        └── maven-status
            └── maven-compiler-plugin
                └── compile
                    └── default-compile
                        ├── createdFiles.lst
                        └── inputFiles.lst
    
    30 directories, 17 files
    

    Clearly tree has better output, but I would like it to use my .gitignore file. So that my compiled content doesn't show

提交回复
热议问题