git-svn - #object# doesn't exist in the repository at /opt/local/libexec/git-core/git-svn line 4706

后端 未结 3 1437
抹茶落季
抹茶落季 2021-02-04 06:48

on

git svn dcommit

it starts commiting and then I get this

A   spec/controllers/authenticated_system_spec.rb
A   spec/controlle         


        
相关标签:
3条回答
  • 2021-02-04 07:14

    This method does essentially the same as the accepted answer from @VonC but is expanded to make it easier to follow.

    The situation

    This is the error I was getting when issuing git svn dcommit

    #object# doesn't exist in the repository at /usr/lib/git-core/git-svn line 5305
    Failed to read object #object# at /usr/lib/git-core/git-svn line 922
    

    I had a number of commits in git that I was attempting to push upstream, and#object# was the SHA1 hash id of one of those commits 2d061be916dc4c2d54eed7b169f1dd80ecf04bc4 in my case.

    I had included several other git repos from another sources into my project tree. While I hadn't explicitly added them as git submodules I did git add <existing_repo_path>. git notices the .git file and adds existing_repo_path as a special case directory (i.e. as a submodule). These directories are the herring bones that cause git-svn to choke.

    To Fix

    find . -name .git
    

    This will find any directory that was added as a submodule.

    ./.git   # Expect this one
    ./path/to/submodule1/.git
    ./path/to/other/submodule/.git
    

    Remove the special directories from git while leaving the files on the filesystem:

    git rm --cached ./path/to/submodule1 
    git rm --cached ./path/to/other/submodule
    

    Rename or delete the .git files from the submodule directories. Renaming the .git files offers a little bit of protection since you could revert back.

    mv path/to/submodule1/.git path/to/submodule1/dot.git
    mv path/to/other/submodule/.git path/to/other/submodule/dot.git
    

    If you had explicitly added submodules you may need to remove the .gitmodules file at the root of the repo. You should probably edit this file first to check if there is anything in it you want before removing it.

    git rm .gitmodules
    

    The submodule directories can now be added back into git and will be treated as ordinary subtrees (i.e. no longer submodules or special case directories).

    git add ./path/to/submodule1  ./path/to/other/submodule
    

    Commit these new files.

    git commit -a -m "Changed submodules to ordinary directories"
    

    The head of the git repo is now good. But git-svn will still choke because it will attempt to create versions from the git history. This means the git history needs to be changed. My approach is to squash all of the git commits made since the last successful git svn dcommit into a single commit. That way the new single commit will contain only the current head and not the troublesome 'submodule' versions.

    To find the last successful svn commit use:

    git svn log -n 1 --show-commit
    

    I get something like:

    r2917 | 094ed52 | rue | 2015-12-04 15:39:58 +0000 (Fri, 04 Dec 2015) | 2 lines
    <commit message>
    

    The output shows the SVN number (r2917) followed by the equivalent git commit id (094ed52)

    Next start an interactive rebase of all the versions since this commit:

     git rebase -i 094ed52
    

    This will open an editor with something like this:

    pick 16b5fcc Changed submodules to ordinary directories
    pick c964dea Some changes
    pick 06cf8ee Added some things
    pick 094ed52 Some other changes
    

    pick means keep this commit, squash means include these changes into the next commit. Replace all 'pick' with 'squash' except the first line.

    pick 16b5fcc Changed submodules to ordinary directories
    squash c964dea Some changes
    squash 06cf8ee Added some things
    squash 094ed52 Some other changes
    

    Save and exit this file and you should get a new single commit.

    git svn dcommit
    

    Now works!

    0 讨论(0)
  • 2021-02-04 07:21

    Did you create submodules in your Git repo ?
    This blog post seems to mention that as an issue.

    As of Jan 2009 git-svn does NOT work with submodules.
    There is no good way to map submodules to svn and the perl script that implements git-svn just bombs when doing git svn dcommit.

    You need to go back and rewrite history.
    You should be able to use git commit --amend.

    $ git tag bad mywork~5
    $ git checkout bad
    $ # make changes here and update the index
    $ git commit --amend
    $ git rebase --onto HEAD bad mywork
    
    0 讨论(0)
  • 2021-02-04 07:22

    I had this same problem (where I had done a git clone and I'm using git svn). Here's the command I used to remove the submodule:

    git filter-branch --index-filter \
    'git rm --cached --ignore-unmatch path/to/the/formerly/misbehaving/module'
    

    I found this wonderful solution on this blog

    0 讨论(0)
提交回复
热议问题