William Shallum

git-svn interrupted dcommit (disconnect)

Posted Feb 25 2010, 16:10 by William Shallum [updated May 13 2013, 02:09]

Given my flaky internet connection, it is no surprise that it decided to drop the signal in the middle of a git svn dcommit. After I interrupted the process using Ctrl-C, git status showed a lot of uncommited changes. Uh-oh. Where did my commits go?

$ git svn dcommit
some/file: needs update
some/other/file: needs update
M some/file
M some/other/file
Committed r98
<internet connection drops here, Ctrl-C pressed>
$ git svn dcommit
Cannot dcommit with a dirty index. Commit your changes first, or stash them with `git stash'.
at /usr/bin/git-svn line 415

$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# modified: some/file
# modified: another/file
# modified: yet/another/redacted/file
no changes added to commit (use "git add" and/or "git commit -a")

To fix this, search .git/logs/HEAD for a commit ID (or use git reflog). Here are the relevant lines from my .git/logs/HEAD file (towards the bottom).

62ad9df05eea6ac60fa39be213604596e3c05ceb 866fd153d0f5a457ce9f76c8e1b3a9752bf38663 William Shallum <my-email-address> 1235659917 +0000 rebase: <commit message redacted>
866fd153d0f5a457ce9f76c8e1b3a9752bf38663 96153576e273e1f0f1a95e485fc69f35a71eda32 William Shallum <my-email-address> 1235660040 +0000 refs/remotes/git-svn: updating HEAD
96153576e273e1f0f1a95e485fc69f35a71eda32 62354d5bc4fede8bd7effa6362ecb9c4f177205e William Shallum <my-email-address> 1235660099 +0000 refs/remotes/git-svn: updating HEAD

Now, I need to get it back to the commit 866fd153d0f5a457ce9f76c8e1b3a9752bf38663. git checkout will do that nicely.

$ git checkout 866fd153d0f5a457ce9f76c8e1b3a9752bf38663
Note: moving to "866fd153d0f5a457ce9f76c8e1b3a9752bf38663" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
HEAD is now at 866fd15... <commit message redacted>

Now I’m … nowhere… This is a detached head situation.

$ git status
# Not currently on any branch.

Now to make this the HEAD of my master branch:

$ git rebase --onto HEAD 866fd153d0f5a457ce9f76c8e1b3a9752bf38663 master
First, rewinding head to replay your work on top of it...
Nothing to do.

Now, git log seems to show all the relevant commits, and I’m once more a happy git user. To continue working with git svn, I need to do git svn fetch and git svn rebase. Only after issuing those two commands can I git svn dcommit.

$ git svn dcommit
Committing to http://my-svn-server/my-repo/trunk
Merge conflict during commit: File or directory 'one/of/my/files' is out of date; try updating: resource out of date; try updating at /usr/bin/git-svn line 461
$ git svn fetch
$ git svn rebase
First, rewinding head to replay your work on top of it...
Applying <one of my commits>
Applying <another commit>
Applying <yet another commit>
$ git svn dcommit
<appears to hang due to stupid Internet connection, but eventually works>

If this often happens, I suppose this workflow by Imran M Yousouf might be worth trying.