What to do when ‘git svn dcommit’ Fails on you?

After I created a new release of OMGF, I ran git svn dcommit to push my local Git commits to the trunk of WordPress’ SVN repository. Needless to say, it failed: a pre-commit hook on the server rejected one of the commits. Git gave up on me and left me behind. git status said I was in the middle of a rebase. Which I didn’t want at all!

The error message git svn dcommit returned was huge, but it did reveal the commit message belonging to the commit causing the error.

I found Ian Dunn’s solution, but I made a few additions so I could resolve my specific issue:

  1. Find the hash of the last commit you made before running dcommit. There are several ways to do this, and Ian suggests opening .git/logs/HEAD. This didn’t help me, because I tried several things after the first time dcommit failed. Instead I noted down the commit message which was mentioned in the error message and ran git log --all --grep="Your Commit Message".  This gave me the hash of the corresponding commit.
  2. Make a back-up of the state your files are currently in (the state in which you initially wanted to commit them) in a different location (!) than your repository.
  3. If you don’t want to look through the entire log, looking for the hash of the commit before everything went to hell, first git reset --hard {hash} to restore the repo to the culprit commit. Then git log and copy the hash of the second entry in its output. Then git reset --hard {hash} again.
  4. Then git svn rebase so that git-svn will recognize if any of the commits were successfully pushed to the server and not try to re-push them.
  5. Then git push --force to make sure your local and remote branches are the same.
  6. Copy back your files from your backup location to the location of your repository.
  7. Now just run git svn dcommit, it should work just fine with (most of) your Git log intact.

❤️ it? Share it!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Shopping Cart
  • Your cart is empty.