-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
$ export RUST_BACKTRACE=1 | ||
$ git init -q 1> /dev/null | ||
|
||
$ echo contents1 > file1 | ||
$ git add . | ||
$ git commit -m "add file1" 1> /dev/null | ||
|
||
$ git log --graph --pretty=%s | ||
* add file1 | ||
|
||
$ git checkout -b branch2 | ||
Switched to a new branch 'branch2' | ||
|
||
$ echo contents2 > file1 | ||
$ git add . | ||
$ git commit -m "mod file1" 1> /dev/null | ||
|
||
$ echo contents3 > file3 | ||
$ git add . | ||
$ git commit -m "mod file3" 1> /dev/null | ||
|
||
$ git checkout master | ||
Switched to branch 'master' | ||
|
||
$ echo contents3 > file2 | ||
$ git add . | ||
$ git commit -m "add file2" 1> /dev/null | ||
|
||
$ git merge -q branch2 --no-ff | ||
|
||
$ git log --graph --pretty=%H | ||
* 1d69b7d2651f744be3416f2ad526aeccefb99310 | ||
|\ | ||
| * 86871b8775ad3baca86484337d1072aa1d386f7e | ||
| * 975d4c4975912729482cc864d321c5196a969271 | ||
* | e707f76bb6a1390f28b2162da5b5eb6933009070 | ||
|/ | ||
* 0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb | ||
|
||
$ josh-filter -s :start=975d4c4975912729482cc864d321c5196a969271[:prefix=x/y] --update refs/heads/filtered | ||
[2] :prefix=x | ||
[2] :prefix=y | ||
[5] :start=975d4c4975912729482cc864d321c5196a969271[:prefix=x/y] | ||
|
||
$ git log --graph --decorate --pretty=%H refs/heads/filtered | ||
* 8b4097f3318cdf47e46266fc7fef5331bf189b6c | ||
|\ | ||
| * ee931ac07e4a953d1d2e0f65968946f5c09b0f4c | ||
| * cc0382917c6488d69dca4d6a147d55251b06ac08 | ||
| * 9f0db868b59a422c114df33bc6a8b2950f80490b | ||
* e707f76bb6a1390f28b2162da5b5eb6933009070 | ||
* 0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
$ git init -q 1>/dev/null | ||
|
||
Initial commit of main branch | ||
$ echo contents1 > file1 | ||
$ git add . | ||
$ git commit -m "add file1" 1>/dev/null | ||
|
||
Initial commit of subtree branch | ||
$ git checkout --orphan subtree | ||
Switched to a new branch 'subtree' | ||
$ rm file* | ||
$ echo contents2 > file2 | ||
$ git add . | ||
$ git commit -m "add file2 (in subtree)" 1>/dev/null | ||
$ export SUBTREE_TIP=$(git rev-parse HEAD) | ||
|
||
Articially create a subtree merge | ||
(merge commit has subtree files in subfolder but has subtree commit as a parent) | ||
$ git checkout master | ||
Switched to branch 'master' | ||
$ git merge subtree --allow-unrelated-histories 1>/dev/null | ||
$ mkdir subtree | ||
$ git mv file2 subtree/ | ||
$ git add subtree | ||
$ git commit -a --amend -m "subtree merge" 1>/dev/null | ||
$ tree | ||
. | ||
|-- file1 | ||
`-- subtree | ||
`-- file2 | ||
|
||
1 directory, 2 files | ||
$ git log --graph --pretty=%s | ||
* subtree merge | ||
|\ | ||
| * add file2 (in subtree) | ||
* add file1 | ||
|
||
Change subtree file | ||
$ echo more contents >> subtree/file2 | ||
$ git commit -a -m "subtree edit from main repo" 1>/dev/null | ||
|
||
Rewrite the subtree part of the history | ||
FIXME(RalfJung): if I use /subtree or subtree/, the command still succeeds, but produces completely wrong output | ||
$ josh-filter -s :start=$SUBTREE_TIP[:prefix=subtree] refs/heads/master --update refs/heads/filtered | ||
[1] :prefix=subtree | ||
[4] :start=c036f944faafb865e0585e4fa5e005afa0aeea3f[:prefix=subtree] | ||
|
||
$ git log --graph --pretty=%s refs/heads/filtered | ||
* subtree edit from main repo | ||
* subtree merge | ||
|\ | ||
| * add file2 (in subtree) | ||
* add file1 | ||
|
||
Compare input and result. ^^2 is the 2nd parent of the first parent, i.e., the 'in subtree' commit. | ||
$ git ls-tree --name-only -r refs/heads/filtered | ||
file1 | ||
subtree/file2 | ||
$ git diff refs/heads/master refs/heads/filtered | ||
$ git ls-tree --name-only -r refs/heads/filtered^^2 | ||
subtree/file2 | ||
$ git diff refs/heads/master^^2 refs/heads/filtered^^2 | ||
diff --git a/file2 b/subtree/file2 | ||
similarity index 100% | ||
rename from file2 | ||
rename to subtree/file2 | ||
|
||
Extract the subtree history | ||
$ josh-filter -s :start=$SUBTREE_TIP[:prefix=subtree]:/subtree refs/heads/master --update refs/heads/subtree | ||
[1] :prefix=subtree | ||
[4] :/subtree | ||
[4] :start=c036f944faafb865e0585e4fa5e005afa0aeea3f[:prefix=subtree] | ||
$ git checkout subtree | ||
Switched to branch 'subtree' | ||
$ cat file2 | ||
contents2 | ||
more contents | ||
|
||
Work in the subtree, and sync that back. | ||
$ echo even more contents >> file2 | ||
$ git commit -am "add even more content" 1>/dev/null | ||
$ josh-filter -s :start=$SUBTREE_TIP[:prefix=subtree]:/subtree refs/heads/master --update refs/heads/subtree --reverse | ||
[1] :prefix=subtree | ||
[4] :/subtree | ||
[4] :start=c036f944faafb865e0585e4fa5e005afa0aeea3f[:prefix=subtree] | ||
$ git log --graph --pretty=%s refs/heads/master | ||
* add even more content | ||
* subtree edit from main repo | ||
* subtree merge | ||
|\ | ||
| * add file2 (in subtree) | ||
* add file1 | ||
$ git ls-tree --name-only -r refs/heads/master | ||
file1 | ||
subtree/file2 | ||
$ git checkout master | ||
Switched to branch 'master' | ||
$ cat subtree/file2 | ||
contents2 | ||
more contents | ||
even more contents | ||
|
||
And then re-extract, which should re-construct the same subtree. | ||
$ josh-filter -s :start=$SUBTREE_TIP[:prefix=subtree]:/subtree refs/heads/master --update refs/heads/subtree2 | ||
[1] :prefix=subtree | ||
[5] :/subtree | ||
[5] :start=c036f944faafb865e0585e4fa5e005afa0aeea3f[:prefix=subtree] | ||
$ test $(git rev-parse subtree) = $(git rev-parse subtree2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters