Search code examples
gitwindows-10git-bash

Fatal: input format error for git mktree command


I am using Git Bash on Windows 10, and I was learning to create a Git tree object. So, what I did was made two blobs of the following hashes:

4400aae52a27341314f423095846b1f215a7cf08
b7aec520dec0a7516c18eb4c68b64ae1eb9b5a5e

Both blobs have the permission 100644. Now, I made a file on Desktop as temp-tree.txt and added the following blobs with their respective parameters as:

100644 blob b7aec520dec0a7516c18eb4c68b64ae1eb9b5a5e file1.txt
100644 blob 4400aae52a27341314f423095846b1f215a7cf08 file2.txt

I saved it as temp-tree.txt. Now, in the Git Bash terminal, in the master folder, I entered the following command:

cat ../temp-tree.txt | git mktree

but it resulted in an error:

fatal: input format error: 100644 blob b7aec520dec0a7516c18eb4c68b64ae1eb9b5a5e file1.txt

How do I correct it?

I tried using TAB, but it gave this as output:

cat ../temp-tree.txt
100644 blob b7aec520dec0a7516c18eb4c68b64ae1eb9b5a5e    file1.txt
100644 blob 4400aae52a27341314f423095846b1f215a7cf08    file2.txt

cat ../temp-tree.txt | git mktree
fatal: input format error: (blank line only valid in batch mode)

Solution

  • tl;dr: use a tab between the hash and the filename, and make sure that the file has Unix-style (\n) line endings.

    git mktree's manual page indicates that it:

    Reads standard input in non-recursive ls-tree output format

    And git ls-tree's manual page indicates that this format is:

    <mode> SP <type> SP <object> TAB <file>

    Your file looks like it has a SP (space) between the <object> and the <file>, not a TAB.


    You also say that you "created the file" but do not provide additional details. If you created it with - say - Notepad, then the file almost certainly has DOS-style (\r\n) line endings. git will not tolerate this.

    You'll need to convert this file to have Unix style line endings using a tool like dos2unix (included with Git for Windows) or a text editor (in vim, you would :set ff=unix and then save the file and exit with :wq).