Was bored, decided to write down how to manually commit a new file in git (there...
Ity Kitty [unit X-69] - VIOLENT FUCK ⇉ 40C3 @tranquillity@mastodon.minionflo.net
Was bored, decided to write down how to manually commit a new file in git (there's more shenanigans involved for committing a file nested in directories, as you need to construct a tree object depth-first for every directory level)
Deserialize the HEAD commit object, then
deserialize the commit object's tree into a temp file
git cat-file -p (git cat-file -p HEAD | awk '/tree/{print $2}') > /tmp/tree.txt
Hash and write the new file baz.txt, then append it to the temp file
echo -e 100644 blob "$(git hash-object -w baz.txt)\tbaz.txt" >> /tmp/tree.txt
Generate the new commit object
echo -e "tree $(cat /tmp/work.txt | git mktree)\nparent $(git rev-parse HEAD)\nauthor $(git
show -s --format='%an <%ae>') $(date '+%s %z')\ncommitter $(git show -s --format='%an <%ae>') $(date '+%s %z')\n\nCommit 3" > /tmp/newcommit.txt
Set the HEAD of the repo to the new commit
git update-ref refs/heads/master (git hash-object -w -t commit /tmp/newcommit.txt)