I have not been able to find a similar answer to my question.
Situation:
Locally using GIT (git version 1.7.3.1.msysgit.0)
Remote repository is SVN (not sure of version)Problem:
Clone an SVN repo, add a folder, commit it to git and SVN, rename the folder (without telling git), commit to git, cannot commit anymore to SVN.
Issue Steps (SVN repo has one file in it main.as in the root folder)
- clone branch from SVN repo (now have one file locally)
- commit to git locally (including
git add .
) - create oldFolder with a file in it
- commit to git locally (including
git add .
) - dcommit to SVN
- rename oldFolder -> newFolder (rename with IDE or manually - not
git-mv
) - commit to git locally (including
git-add .
) - dcommit to SVN (don't need SVN rebase since I'm the only one committing changes to SVN)
PROBLEM: The git-svn dcommit responds:
oldFolder/file.txt: needs update
update-index --refresh: command returned error: 1
What I tried:
- stash, commit, dcommit, stash apply (same thing:needs update)
- stash, rebase, stash apply, commit, dcommit (same thing:needs update)
- stash, rebase, stash apply, commit, stash, dcommit (same thing:needs update)
The one that semi-worked was to call:
svn rm -r oldFolder
but this ended up with oldFolder
and newFolder
in SVN... whereas I want oldFolder
to be either renamed or deleted (I don't mind losing the history in this case).
I need the SVN repo to 开发者_JAVA技巧reflect my local git master/branch...
Why am I renaming files without the git command? I work with large file structures and the IDEs that im using for refactoring old code renames multiple folders and files causing the above scenario. I cannot keep track and call git rm on every folder removed.
At step 7, you staged the addition of the new file (newFolder/file.txt) but not the deletion of the old file. You'll need to do the following instead of step 6 and 7 above:
- rename oldFolder -> newFolder (rename with IDE or manually - not git-mv)
- git add newFolder
- git rm -r oldFolder
- commit locally
At this point, git will track renames (if any), and produce a correct commit for SVN.
If your tree is still at step 7, you can do
git reset --soft HEAD~
to return to the previous commit and stage the deletion.
(Adding another answer just for the sake of completeness)
A git add --all
adds all modifications, including deletes and renames.
So the following sequence of commands usually "just works", even in the case of folder renames:
git add --all
git commit -m "some msg"
git svn dcommit
We don't really need to git rm -r OLD_FOLDER
(unless, of course, when we want to fine-tune the Git index definition).
精彩评论