When I git svn rebase
I get this error:
src/thread.cpp: needs update
update-index --refresh: command returned error: 1
That file uses unix line endings. The diff shows one line had CRLF which was removed. When I git reset --hard HEAD
, the file is still marked as modified with the same change. Presumably because git automatically transforms the newlines. I sometimes see this warning:
warning: in the working copy of ‘src/thread.cpp’, CRLF will be replaced by LF the next time Git touches it
I use autocrlf=false
, but I’ve also tried reset + status with input
and true
.
Additional detail: the offending file has an eol attribute but not all source files do. (I believe this attribute comes from an svnprop.)
$ git check-attr -a source/game.cpp src/thread.cpp src/math.cpp
src/thread.cpp: eol: lf
src/math.cpp: eol: lf
Edit: Ran into this on a different branch and my below rebase solution didn’t work, but I found a new solution.
Avoid the problem and don’t touch the working copy. If your svn remote uses the default origin/trunk
:
:: First fix the line ending in svn.
dos2unix src/thread.cpp
svn add src/thread.cpp
svn commit -m"Use consistent line ending"
:: Get that new history so we have a good state to reset to.
git svn fetch
git reset --hard origin/trunk
Original solution:
I used an svn checkout to remove the offending line and submit.
Then, I deleted the offending file before git reset
and so autocrlf
applies to the file. This didn’t seem to work 100% — I had to run this script more than once before it worked (but earlier version used git status -uno --porcelain
before git svn rebase
):
git config core.autocrlf true
git rm --force src/thread.cpp
git reset --hard HEAD
git svn rebase
The rebase aborts when it gets to the svn commit that fixed the line ending, but I have it as a git commit so I can git reset --hard origin/trunk
and be able to git svn rebase
once again! I also made sure to run the above script but with core.autocrlf false
to switch back to not changing line endings.