13

This is a noob question but I'm under the gun to resolve this. I've inherited an odd problem with a git subtree that appears to be repo corruption.

Here's the scenario : a subtree of a git-based project A is being used in project B. Part of the deploy script use pushes the subtree out to project B's repo:

git subtree push -P sub/path/name --squash git@github.com:MyCo/project_b.git projectb_branch

it starts pushing the commits and fails with

"fatal: bad object {sha}" 

I've searched for the SHA in the source repo's git log. It shows up in a commit:

git-subtree-dir: app/assets/ui
git-subtree-split: {sha}

The target repo (project_b) does indeed have a commit with that SHA but the source repo does not. I walked through the subtree shell script I can see that it's failing when it tries to look up that object with git log (in the toptree_for_commit function calling git log -l --pretty=format:'%T' {sha}).

At this point I am in way over my head but eager to try to find a solution. I've researched this as far as my limited knowledge permits, so I welcome any tips, tricks or RTFMs that can get me a little closer to a solution.

my sincere thanks!

Kodez Monkey
  • 171
  • 1
  • 8

4 Answers4

23

I just ran into this issue and was able to resolve by:

git remote add shared $url
git fetch shared
git subtree push -P $prefix shared $branch

Might not help for all but saved me from having to hack on the repo structures.

Kevin Decker
  • 2,235
  • 1
  • 17
  • 17
  • 3
    Just to clarify, for the noobs like me $url, $prefix, and $branch need to be filled in with your own proper url, prefix, and branch. – lnhubbell Feb 26 '15 at 18:11
4

I came across similar issue: git subtree push ... used to work on the computer, where I did git subtree add ..., but wouldn't work on second computer:

$ git subtree push --prefix lib git@github.com:lib/lib.git master
...
...
fatal: bad object {sha} 

Fix was to pull changes from the repository first (even though there were no changes):

git subtree pull --prefix lib git@github.com:lib/lib.git master

and even though it didn't pull anything, push worked fine then:

git subtree push --prefix lib git@github.com:lib/lib.git master
petrkotek
  • 4,541
  • 1
  • 18
  • 15
3

I have figured this out; I found the reference of the errant sha in the commit information.

The easiest way to fix this is to:

  • stop using the subtree split that'd been created,
  • move the content to a different subdirectory and then
  • resplit the subtree.

Kind of messy but much less error prone than backing out commits to the problematic commit and then reapplying them (suggested in an answer to a somewhat similar question).

Not beautiful, but it got the job done.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Kodez Monkey
  • 171
  • 1
  • 8
0

git pull worked for me. If your current branch is not a remote one, make it a remote branch using

`git push -u origin <branchname>`
saada
  • 2,612
  • 3
  • 27
  • 33