3

I started to using subtree but ended in mess now. Googling and the man page didn't help that I can find out how to solve this error. Anyone an idea?

Error:

➜ git subtree split -P gitkraken --rejoin
cache for 12d7b0ee9414ebd0414070d22fb40db7446badd9 already exists!

Example to reproduce it, externally.

mkdir test
cd test
git init
touch readme.md
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git add readme.md
git commit -m "add readme"
git subtree add --prefix gitkraken "aur@aur.archlinux.org:gitkraken.git" master
git subtree split -P "gitkraken" --rejoin

Currently, in my repo I switched the folder to gitkraken-aur and so it works for the moment again.

Attempt from the first answer to remove the subtree folder.

test on  main [?]
➜ rm -rf .git/subtree-cache

test on  main [?]
➜ git subtree split -P "gitkraken" --rejoin

cache for 12d7b0ee9414ebd0414070d22fb40db7446badd9 already exists!

test on  main [?]
➜ git subtree pull -P gitkraken "aur@aur.archlinux.org:gitkraken.git" master -m "Merge subbtree gitkraken"
From aur.archlinux.org:gitkraken
 * branch            master     -> FETCH_HEAD
Already up to date.

test on  main [?]
➜ git subtree push -P gitkraken "aur@aur.archlinux.org:gitkraken.git" master
git push using:  aur@aur.archlinux.org:gitkraken.git master
cache for 12d7b0ee9414ebd0414070d22fb40db7446badd9 already exists!

test on  main [?]
➜ rm -rf .git/subtree-cache

test on  main [?]
➜ git subtree push -P gitkraken "aur@aur.archlinux.org:gitkraken.git" master
git push using:  aur@aur.archlinux.org:gitkraken.git master
cache for 12d7b0ee9414ebd0414070d22fb40db7446badd9 already exists!

More debug information to attempt one.

test on  main [?]
➜ rm -rf .git/subtree-cache

test on  main [?]
➜ tree .git
.git
├── COMMIT_EDITMSG
├── FETCH_HEAD
├── HEAD
├── ORIG_HEAD
├── branches
├── config
├── description
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── fsmonitor-watchman.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── pre-merge-commit.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   ├── pre-receive.sample
│   ├── prepare-commit-msg.sample
│   ├── push-to-checkout.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       └── heads
│           └── main
├── objects
│   ├── 0c
│   │   └── ce20ac9c41edfaafd245059b066f4e644b6c84
│   ├── 23
│   │   └── 9ec593c6a2192e76c005435f748b2ad28be832
│   ├── 69
│   │   └── 3d7dd0cbe326ad51fffad7408c2c6cc8af7e0d
│   ├── 74
│   │   └── 11ec84b161eba98f6ae09d2210c231393c977c
│   ├── 84
│   │   └── a5dcf23e618a493da589f95f2c57da22603e2a
│   ├── 99
│   │   └── 03d6d6b962b96143f3e2c0b75550561de14c06
│   ├── b3
│   │   └── 5caa9cbb57f55fb05260b3dd767f92c62a20ba
│   ├── bf
│   │   └── 52649a7b94057b0da0a7f1bb20c55b395717be
│   ├── e4
│   │   └── 22b2b19b0c80773ccbad0822130158a024ef59
│   ├── e6
│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│   ├── eb
│   │   └── 4c7f2ebf6596f7e3c40b2355bc11e7a1badf58
│   ├── info
│   └── pack
│       ├── pack-542055b17c2fb18100e23d143d0f824b0c5ee19f.idx
│       └── pack-542055b17c2fb18100e23d143d0f824b0c5ee19f.pack
└── refs
    ├── heads
    │   └── main
    └── tags

23 directories, 37 files

test on  main [?]
➜ git subtree split -P "gitkraken" --rejoin

cache for 12d7b0ee9414ebd0414070d22fb40db7446badd9 already exists!

test on  main [?]
➜ tree .git
.git
├── COMMIT_EDITMSG
├── FETCH_HEAD
├── HEAD
├── ORIG_HEAD
├── branches
├── config
├── description
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── fsmonitor-watchman.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── pre-merge-commit.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   ├── pre-receive.sample
│   ├── prepare-commit-msg.sample
│   ├── push-to-checkout.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       └── heads
│           └── main
├── objects
│   ├── 0c
│   │   └── ce20ac9c41edfaafd245059b066f4e644b6c84
│   ├── 23
│   │   └── 9ec593c6a2192e76c005435f748b2ad28be832
│   ├── 69
│   │   └── 3d7dd0cbe326ad51fffad7408c2c6cc8af7e0d
│   ├── 74
│   │   └── 11ec84b161eba98f6ae09d2210c231393c977c
│   ├── 84
│   │   └── a5dcf23e618a493da589f95f2c57da22603e2a
│   ├── 99
│   │   └── 03d6d6b962b96143f3e2c0b75550561de14c06
│   ├── b3
│   │   └── 5caa9cbb57f55fb05260b3dd767f92c62a20ba
│   ├── bf
│   │   └── 52649a7b94057b0da0a7f1bb20c55b395717be
│   ├── e4
│   │   └── 22b2b19b0c80773ccbad0822130158a024ef59
│   ├── e6
│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│   ├── eb
│   │   └── 4c7f2ebf6596f7e3c40b2355bc11e7a1badf58
│   ├── info
│   └── pack
│       ├── pack-542055b17c2fb18100e23d143d0f824b0c5ee19f.idx
│       └── pack-542055b17c2fb18100e23d143d0f824b0c5ee19f.pack
├── refs
│   ├── heads
│   │   └── main
│   └── tags
└── subtree-cache
    └── 24098
        ├── 12d7b0ee9414ebd0414070d22fb40db7446badd9
        ├── 9903d6d6b962b96143f3e2c0b75550561de14c06
        ├── e9aad069b8e1e49f8cbb54cb91e3f226e4949712
        └── notree

26 directories, 40 files
Chandan
  • 11,465
  • 1
  • 6
  • 25
Azd325
  • 5,752
  • 5
  • 34
  • 57

3 Answers3

2

You need to clear the subtree cache by removing the .git/subtree-cache folder. You could always try seaching for the 12d7b0ee9414ebd0414070d22fb40db7446badd9 file inside that folder and remove just that.

And then try again again executing your command.

I was able to reproduce and fix that way, the answer was found by reverse engineering the code causing the error : https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L329

Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
0

I had the same issue and spent many times to solving it.

My co-worker had same problem and after reinstalling git several times, it was solved and I asked him which version he was using.

After downgrading the git version to 2.30.2, 'cache for *** exist' message still appears, but 'subtree push' operation worked successfully

The git version with the problem in my case was 2.35.2

ddubie
  • 21
  • 4
0

I don't know if this will help in debugging this issue, but I am still getting it today with git version 2.39.2.

The way I got to this point was probably by adding git subtrees, then removing them sometime after to re-add the same ones again. I was testing with a monorepo repository.

My feeling is that if somewhere in the history there have been more than one subtree add, this happens:

git subtree push -d --prefix commerce/packages/xx/xx-component-phpmd-config xx-component-phpmd-config main

command: {push}
quiet: {}
dir: {commerce/packages/xx/xx-component-phpmd-config}
opts: {xx-component-phpmd-config main}

git push using:  xx-component-phpmd-config main
Splitting commerce/packages/xx/xx-component-phpmd-config...
Using cachedir: /Users/antonevers/web/xx/xx-monorepo/.git/subtree-cache/12575
Looking for prior splits...
  Main is: '5cc22cd76dc2ddd4fdaf05445ebee23c4705eee1'
    Prior: 5cc22cd76dc2ddd4fdaf05445ebee23c4705eee1 -> ede24f61adf6ce0b1a7853c334470a88f27c7bef
  Main is: '2b41e165071909200abd959fc609aea4c97bcd82'
    Prior: 2b41e165071909200abd959fc609aea4c97bcd82 -> ede24f61adf6ce0b1a7853c334470a88f27c7bef
fatal: cache for ede24f61adf6ce0b1a7853c334470a88f27c7bef already exists!

I have solved the issue by branching off from a part in the history before first adding subtrees. Then started over completely. Thus bypassing the point in history where subtrees have been added to the same path more than once.