31

When I did a git svn rebase it stopped at one point saying:

Index mismatch: SHA key of a tree != SHA key of another tree. (I come to know that these SHA keys corresponds to a tree and not a commit from git show of the above two sha keys.)

re-reading <sha index of a commit in svn/trunk>
... list of files ...
fatal: bad object <SHA1 index of the bad object>
rev-list -1 <SHA1 index of the bad object> --not <SHA1 index of the revision it was trying to re-read>: command returned error: 128

I am not very experienced in the internal workings of git, so is there a sequence of steps to follow to dissect problems like these and possibly resolve them?

5
  • 3
    The first think I would try with a suspected corrupted repository is a git fsck. Commented Nov 1, 2010 at 23:33
  • @Greg-Hewgill: Thanks for your suggestion. I did a git fsck and it listed a bunch of dangling trees, commits and blobs. I am refering to this section in Git user manual: kernel.org/pub/software/scm/git/docs/… and try to figure out what happened in the repo. Fortunately, couple of weeks back I archived my .git folder for my colleague to get up and running with the repo. I used that and created a new repo and continuing with my work while I figure out what happened to the corrupted one.
    – yasouser
    Commented Nov 3, 2010 at 3:26
  • Only thing that I can think of is that someone else possibly rebased before you did, thus changing the SHA key of the remote repo and giving you the error you see now. If you were to pull the changes made to the tree, fix any conflicts, then rebase from there, it might work properly.
    – g19fanatic
    Commented Nov 4, 2010 at 13:27
  • You only saw dangling commits, no missing ones? This is reasonably normal -- dangling commits are created when rebasing and dangling trees when using git add -- the index is maintained as a tree. Commented Nov 4, 2010 at 19:35
  • @g19fanatic The remote repository is an SVN repository, and SVN doesn't support history rewriting, so I'm not sure what you mean
    – Max Nanasy
    Commented Aug 1, 2013 at 18:15

10 Answers 10

39

Please don't remove the .git/svn folder to fix this. It requires you to rebuild everything, it is annoying, it will take awhile (for the size of my repo several hours) and it is NOT NECESSARY.

I found the right answer here and I've included it below.

From the link:

Inside the .git directory run the following:

$ find . -exec grep -Hin 5b32d4ac2e03a566830f30a702523c68dbdf715b {} \;
Binary file ./svn/.caches/lookup_svn_merge.db matches
Binary file ./svn/.caches/check_cherry_pick.db matches

Now delete the matching .svn/.caches from the output of the first command

$ rm ./svn/.caches/lookup_svn_merge.db
$ rm ./svn/.caches/check_cherry_pick.db

Now git svn rebase or git svn fetch to your heart's content.

2
  • 2
    Yes I did find this technique later. During my next attempt I just cleared the caches and it was lot quicker than deleting the .git/svn. Forgot to update here. Thanks for posting your answer.
    – yasouser
    Commented Jan 10, 2013 at 18:46
  • I also had checksum mismatch at the same time in the message and this solution did not fix the problem in such case. Commented Aug 15, 2019 at 8:28
38

I've had this error twice and both times resolved it by removing the svn folder inside the .git folder.

rm -r .git/svn

then rebuild the svn metadata with:

git svn fetch

You will probably see a message along the lines of:

Migrating from a git-svn v1 layout...
Data from a previous version of git-svn exists, but
    .git/svn
    (required for this version (1.7.0.4) of git-svn) does not exist.
Done migrating from a git-svn v1 layout

and after while (rebuilding can take a while especially on large repositories) you should end up with a working mirror of the svn repository again.

9
  • 1
    +1 for simplicity; it's really overkill for large repositories but in most cases an overall time saver. Commented Mar 7, 2011 at 17:26
  • 2
    For my large repository I fetched just some latest commits: "git svn fetch -r 12345:HEAD". I can still see previous commits.
    – Erdem
    Commented May 4, 2012 at 10:27
  • 1
    Definitely overkill and completely unnecessary.
    – Matt Hulse
    Commented Jan 10, 2013 at 17:42
  • 1
    This should come with a warning at a minimum.
    – deuberger
    Commented Oct 18, 2016 at 18:19
  • 1
    Adding --log-window-size=5000 (or larger) will speed up the fetch greatly.
    – Ian Dunn
    Commented Mar 22, 2019 at 21:34
13

Update git client and refetch last svn commits using:

git svn reset -r 12345
git svn rebase

where 12345 is existing svn revision.

1
  • 2
    This worked in a case where fiddling with the .caches directory did not.
    – krlmlr
    Commented Apr 4, 2014 at 21:26
4

In my case, the issue was caused by a new/unknown svn author who was not in my authors file that git-svn was configured to use. It reported it in the output that that I ignored the first few reads:

Index mismatch: <leftsha1> != <rightsha1>
rereading <anothersha1>
        ... list of files ...
Author: <name> not defined in /path/to/authors file

So that gave me the name that I was missing, and what file to add it too (I pulled the email from my organizations user registry) and was smooth sailing.

1

The problem there is that you have to do this systematically in this case :

  • use git + svn
  • create branch on svn with git-svn
  • merge branch to trunk with svn tools
  • remove the svn branch
  • do a git-svn rebase

Something missing, everything crash. The only way I know to recover is do remove all svn in .git and rebuild everything. It's just annoying and take a while !

1

Likely, you may also have Checksum mismatch at the same time in your message:

I found solution here Git svn rebase : checksum mismatch:

git svn log <item with checksum mismatch>
git svn reset -r<top history revision in the log> -p
git svn rebase
0
+50

I just had this error myself. Just delete the ref, like so:

rm .git/refs/remotes/git-svn

That should clear up the error.

4
  • I couldn't find a git-svn under .git/refs/remotes directory!?!?!
    – yasouser
    Commented Nov 5, 2010 at 21:26
  • 1
    Sorry, my mistake. That should be .git/refs/remotes/git-svn. Commented Nov 6, 2010 at 0:14
  • I don't have a git-svn file under .git/refs/remotes directory!?!?!
    – yasouser
    Commented Nov 8, 2010 at 14:13
  • 1
    On second thought, it looks like this is a different issue after all. I had the same "Index mismatch" error, which I fixed by removing the git-svn remote ref, but I didn't get the rest of it. Commented Nov 9, 2010 at 4:51
0

Maybe something to do with Copy-On-Write feature of your filesystem (ext4/btrfs/etc...) ?

See : https://stackoverflow.com/a/42299634/7491491

0

I got this error:

Index mismatch: <sha> != <sha> re-reading <sha index of a commit in svn/trunk> ... list of files ... <path> was not found in commit <sha> (r<svn rev>)

Looking in SVN repo at the history of the reported path, I found the SVN revision where the file had been added. But looking in Git at the commit created for that revision I found that it didn't contain any files!

I think this had been caused by a full disk earlier. After doing a git svn reset -r back to the revision of the broken Git commit, git svn fetch worked fine again.

0

I ran into this during the initial cloning turns out someone created a branch called trunk which conflicted with the real trunk. After ignoring /branches/trunk all worked

Not the answer you're looking for? Browse other questions tagged or ask your own question.