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:
- 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 timedcommit
failed. Instead I noted down the commit message which was mentioned in the error message and rangit log --all --grep="Your Commit Message"
. This gave me the hash of the corresponding commit. - 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.
- 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. Thengit log
and copy the hash of the second entry in its output. Thengit reset --hard {hash}
again. - 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. - Then
git push --force
to make sure your local and remote branches are the same. - Copy back your files from your backup location to the location of your repository.
- Now just run
git svn dcommit
, it should work just fine with (most of) your Git log intact.