create tree without using staging area

In the git internals chapter of git-scm book there is an example of how git tree can be created:

Git normally creates a tree by taking the state of your staging area or index and writing a series of tree objects from it. So, to create a tree object, you first have to set up an index by staging some files.

  • How do I fetch/clone only a few branches using git-svn?
  • How to remove local (untracked) files from the current Git working tree?
  • Git push failed. error: RPC failed; result=56, HTTP code = 0
  • Git commit not possible. There are no staged files
  • How do I fetch my git repository from SourceForge?
  • Git does not ask me for gpg passphrase and fails my commit
  • And then they list commands that I can use to create the tree. My question is whether I can create a tree without using index (staging area)? For example instead of doing this:

    git update-index --add --cacheinfo 100644 83baae618... test.txt

    Use something like this:

    git create tree --add --cacheinfo 100644 83baae618... test.txt

    Update based on Ismail Badawi’s anser:

    $ echo 'making tree' | git hash-object -w --stdin

    and then

    $ echo -e '100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt' | git mktree
    fatal: input format error: 100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt

  • Accidentally reverted to master, lost uncommitted changes
  • Git patch - patch does not apply
  • How to have a buildbot GitPoller change source watch all branches?
  • what does git ignorecase really do? how to checkout respecting file capitalisation?
  • How to embed an updated git-hash into Version.hpp?
  • Git Local Repository All Steps
  • One Solution collect form web for “create tree without using staging area”

    You can use git mktree, like this:

    echo -e "100644 blob 83baae618...\ttest.txt" | git mktree

    (You need to write echo -e because of the literal tab. This is a shell thing, not a git thing).

    Note this creates a tree that only points to 83baae618, so it’s not exactly the same as your update-index invocation, which adds to the index (which typically already points to other things). You can pass multiple lines to git mktree, each line describing one blob or tree.

    Git Baby is a git and github fan, let's start git clone.