twosigma / git-meta

Repository for the git-meta project -- build your own monorepo using Git submodules
http://twosigma.github.io/git-meta
BSD 3-Clause "New" or "Revised" License
216 stars 50 forks source link

Add a command that allows patch git trees (like mktree, but recursively) #854

Closed shijinglu closed 2 years ago

shijinglu commented 2 years ago

Add a command that allows creating a new tree by patching an existing one with the output from "git diff-tree"

Suppose you are in a bare repo, and you want to create a new commit by adding a file, you can run:

echo ':000000 100644 0000000000000000000000000000000000000000 a86fc6156eafad6fd0c40d17752da3232dded9b0 A ts/foo/baz.txt' | patch-tree HEAD

The input should have the same format as the output of "git diff-tree -r --raw".

patch-tree will first upsert foo/bar/baz.txt as a leaf to HEAD's tree, and then recursively running mktree for "foo/bar", "foo/" and then root.

Tree entry change can also be defined by short hand diff:

For example: t1=$(patch-tree -s "commit::ts/modeling/bamboo/core" HEAD) patch-tree -s \ "T:467c15c20ab76a4fc89c6c09b4f047e31d531879:ts/modeling/bamboo/core" $t1

means removing the commit at 'ts/modeling/bamboo/core' and adding its tree (stitch)